Tracking Facebook Referrals
Note: This is an advanced topic that requires knowledge of JavaScript and jQuery. If you're not familiar with JavaScript or jQuery, you'll want to visit W3Schools and refer to their JavaScript and jQuery tutorials before attempting to use the methods outlined below.
Because of how Facebook proxies the request for your Campaign, referrer information is lost. That means you can’t just add Google Analytics tracking code to your Campaign and expect to see where traffic comes from. However, it is possible to track your advertising Campaigns using a special parameter supported by Facebook.
app_data
Facebook supports a parameter - app_data - that can be added to a Campaign URL. All other parameters are ignored by Facebook and not passed on, but app_data is. ShortStack can make data available in a JavaScript object that’s accessible with a Code Widget, if that data is encoded in a certain way.
For example, let’s say we want to add two parameters, campaign and ad_id to a Campaign URL. Normally, the link would look like this:
CAMPAIGN_URL?campaign=test&ad_id=123
As already noted, though, Facebook will ignore those extra parameters and the the extra parameters will never reach the Campaign. It may also make sense to do this:
CAMPAIGN_URL?app_data=campaign=test&ad_id=123
However, the above won’t work either because = and & have a special meaning in URLs, so the data won’t come through intact. To fix this, encode the value for app_data like this:
CAMPAIGN_URL?app_data=campaign%3Dtest%26ad_id%3D123
Replace = with %3D and & with %26 so that all the data is correctly passed through. In addition, when encoded this way, ShortStack automatically parses the values into a convenient JavaScript object (tab_config.ajax).
The example code below will show two values in your browser's console: the campaign and ad_id values placed in the "campaign=" and "ad_id=" parameters of the Campaign URL. Please be aware that the example code below should only be used for testing and verification.
<script type="text/javascript"> $(function(){ if (tab_config.ajax.campaign) { console.log('campaign = ' + tab_config.ajax.campaign + '\n' + 'ad_id = ' + tab_config.ajax.ad_id); } }); </script>
Using the app_data parameters
What you do with the values that are in tab_config.ajax is up to you and will depend on what you’re trying to accomplish. In all cases, you’ll need to use a little JavaScript. Here are some ideas:
- Add the parameters to outgoing links (for example, links to your website) so that actions which take place on your website can be credited to the originating ads.
- Create and insert a one-pixel, dynamic tracking image URL.
- Using the Google Analytics API and add the parameters to track the page view.