Facebook Share/Like & URL Issue
5 posts by 3 authors in: Forums > CMS Builder
Last Post: March 7, 2013 (RSS)
Hi,
I've added fb like buttons across my website. When users like an article, fb generally adds a bunch of tags/parameters to the URL and when users click the link on facebook, they are given an error message: Record Not Found!
THis is how a shared/liked link looks like: http://www.illumemagazine.com/zine/articleDetail.php?The-Black-History-of-the-White-House-13745&fb_action_ids=4681431706510&fb_action_types=og.likes&fb_source=timeline_og&action_object_map=%7B%224681431706510%22%3A10150322600590421%7D&action_type_map=%7B%224681431706510%22%3A%22og.likes%22%7D&action_ref_map=[]
Is there a work around? Any suggestions?
Thanks!
Hi,
The best way to work around this is to change your code so that it uses a fixed variable in the URL, and not the last number in the URL. So you could change your URLS to look something like this:
http://www.illumemagazine.com/zine/articleDetail.php?num=13745
or if you wanted to keep the SEO friendly url, you could use something like this:
Then if your using a getRecords function, you will need to change it so that it retrieves records based on the num value as opposed to the using the number at the end of the URL. Something like this should do the trick:
<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
/* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */
// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('C:/wamp/www/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }
$num = @intval($_REQUEST['num']);
// load record from 'blog'
list($blogRecords, $blogMetaData) = getRecords(array(
'tableName' => 'blog',
'where' => $num,
'loadUploads' => true,
'allowSearch' => false,
'limit' => '1',
));
$blog = @$blogRecords[0]; // get first record
if (!$blog) { dieWith404("Record not found!"); } // show error message if no record found
Thanks
Greg
PHP Programmer - interactivetools.com
Ah. That makes sense. Thank you Greg.
I will update the code. But that would mean that all the social sharing tracking count will restart based on the new URLs... Let me see if there's a way to tweak the fb share code so the long string isn't added in the URL..
By Dave - March 5, 2013 - edited: March 7, 2013
Hi Javed,
Thanks for bringing this to our attention. It looks like there is no way to get Facebook to not add extra content to the url so we're working on a patch for the next version that works around this.
If you'd like to try it out early and you are comfortable making PHP code edits you can do the following:
- Open /lib/viewer_functions.php
- Search for _utm
- Replace this:
// remove google utm_ campaign tracking values from url as they might contain numbers. utm names: http://www.google.com/support/googleanalytics/bin/answer.py?answer=55578
$urlData = preg_replace("/&utm_\w+=[^&]*/", '', $urlData);
- With this:
// 2.52 - remove 3rd party field-value pairs from query string as they might contain trailing numbers
$removeFields = array(
'utm_source','utm_medium','utm_term','utm_content','utm_campaign', // google utm names: http://www.google.com/support/googleanalytics/bin/answer.py?answer=55578
'fb_source','fb_action_ids','fb_action_types','fb_ref','fb_aggregation_id', // facebook parameter names: https://developers.facebook.com/docs/technical-guides/opengraph/link-parameters/
'action_object_map','action_type_map','action_ref_map', // additional facebook parameters
);
foreach ($removeFields as $removeField) { $urlData = preg_replace("/&$removeField=[^&]*/", '', $urlData); }
Let me know if that works for you.
interactivetools.com
By Dave - March 7, 2013
Hi All,
Just an update that this code is now in 2.52 beta 1 and will be in the official release.
Thanks!
interactivetools.com