Home > Paid Traffic Sources > Facebook & Instagram

N00b Question on Tracking (20)


11-17-2012 01:00 AM #1 partner (Member)
N00b Question on Tracking

Ok So here's the setup

Sending FB ads to Page tab
Trying to track 1 extra variable ( ad id, demo etc )
Tracking platform cpvlab


Can it be done? Can I pass one extra variable? Old thread I found from 2011 says it cannot, has it changed in a year, seems with sponsored story it can by adding url values, but am looking for regular ad.

Possible?


11-17-2012 03:08 AM #2 zeno (Administrator)

//WARNING: I am sitting around at LAX (8hr layover) so prepare for something lengthy.

To pass some values to a FB page tab app or any app you need to pass these with the app_data querystring, i.e. URL has to have ?app_data=xxxx in it. Facebook passes this data through the iFrame (as JSON that you have to decode/split apart) allowing the page inside to collect and use it, which requires using a signed request. You can pass as many variables as you want, limited by overall characters in the string. I think you can only do this for a page ad via an API client, but you can edit the URL of an app advert normally. Might have to use power editor, FB is changing their system so often shit just disappears, I don't use it so dunno.

So for each page tab app advert you could append a specific &app_data=XXX value and pass that through for tracking. Also for page post ads you can do some funky stuff with replacing tokens in the post's URL but I don't think it's what you're after.

Here's a quick tut and some scriptin shizzle from my vault:

Create an app advert and append tracking variables to URL in the following form:

http://www.facebook.com/pages/pagename/123456789012345?sk=app_PAGE_APP_ID&app_data={"vari able1":"value1","variable2":"value2","variable3":" value3"}

The app_data string is in JSON form and MUST MUST MUST be correctly written. If it is not it will not work. Quotes around first variable name, then a colon, then quote marks around value, then a comma, repeat. No spaces. No Mistakes.

This app_data stuff will be passed into the page tab iFrame so your page inside can get all of that data, decode it, then split it up into parts hoooray for you to tack on to some affiliate/tracking URL. How to do that? First you need to retrieve a signed_request that FB passes, otherwise you can't get this data from FB. Then you decode it, get the JSON baby (the array of variables), then you explode it into little parts and do some magics.

[PHP]
<?php
$signed_request = $_REQUEST['signed_request']; // Get the signed_request data that FB passes (lots of shit)
$pre = explode('.',$signed_request); // Get the part of the signed_request we need.
$json = base64_decode($pre['1']); // Base64 Decode signed_request making it JSON again.
$obj = json_decode($json,true); // Split the JSON into arrays.
$app_data = json_decode($obj['app_data'],true); // Get out just the app_data part
$variable1 = $app_data['variable']; // Pull out the value attached to our first variable in the array and set it to something for later use.
$otherparameter = $app_data['parameter name']; //And so on..
[/PHP]

Now, if I was you, I would make your page tab content some script that has all this in there and in the body echoes the variables so you can create an advert > preview > test it is working, play around etc. If I recall rightly FB also gives your page tab access to a small amount of user data like gender?, age range and country. You should be able to see these if you just echo the entire $signed_request or $app_data, bleh I dunno one of those. Anyway these may come in handy, useful when people come not via adverts so you can at least get some info.

To do this you can decode everything then use if(isset($variable)) to check if someone has some value you passed via app_data, and if they don't, you just set everything differently.

[PHP]
$pre = explode('.',$signed_request);
$json = base64_decode($pre['1']);
$obj = json_decode($json,true);
$app_data = json_decode($obj['app_data'],true);
$user = $obj['user']; //array of some user data
$age0 = $user['age']; //ignore
$age = $age0['min']; //age range methinks
$country = $user['country'];
[/PHP]

Can't remember how you get gender. This is getting way too long winded and I'm soon to leave LAX so I will call it quits here. Enjoy playing with PHP.


11-17-2012 08:57 AM #3 Oded Abbou (Member)

@zeno... you're the man!!! you should be elected!


11-17-2012 08:15 PM #4 zeno (Administrator)

Elected president of New Zealand, and super governor of Ostraliya right? I had this shizzle setup for some fanpage campaigns + dynamic split testing with Clicky. Was testing passing of advert tracking data and subids for BuyBuddy so there was some intense coding going on. Looking back it's hard for even me to figure out my site files, lols. But what I had was a single fanpage tab which had split testing of landers + subids passed for tracking in the lander + redirection to generic page if they came organically, with general user data then pulled to fill in the tracking gaps/collect data.


11-26-2012 09:13 PM #5 partner (Member)

Quote Originally Posted by zeno View Post
//WARNING: I am sitting around at LAX (8hr layover) so prepare for something lengthy.

To pass some values to a FB page tab app or any app you need to pass these with the app_data querystring, i.e. URL has to have ?app_data=xxxx in it. Facebook passes this data through the iFrame (as JSON that you have to decode/split apart) allowing the page inside to collect and use it, which requires using a signed request. You can pass as many variables as you want, limited by overall characters in the string. I think you can only do this for a page ad via an API client, but you can edit the URL of an app advert normally. Might have to use power editor, FB is changing their system so often shit just disappears, I don't use it so dunno.

So for each page tab app advert you could append a specific &app_data=XXX value and pass that through for tracking. Also for page post ads you can do some funky stuff with replacing tokens in the post's URL but I don't think it's what you're after.

Here's a quick tut and some scriptin shizzle from my vault:

Create an app advert and append tracking variables to URL in the following form:

http://www.facebook.com/pages/pagename/123456789012345?sk=app_PAGE_APP_ID&app_data={"vari able1":"value1","variable2":"value2","variable3":" value3"}

The app_data string is in JSON form and MUST MUST MUST be correctly written. If it is not it will not work. Quotes around first variable name, then a colon, then quote marks around value, then a comma, repeat. No spaces. No Mistakes.

This app_data stuff will be passed into the page tab iFrame so your page inside can get all of that data, decode it, then split it up into parts hoooray for you to tack on to some affiliate/tracking URL. How to do that? First you need to retrieve a signed_request that FB passes, otherwise you can't get this data from FB. Then you decode it, get the JSON baby (the array of variables), then you explode it into little parts and do some magics.

[PHP]
<?php
$signed_request = $_REQUEST['signed_request']; // Get the signed_request data that FB passes (lots of shit)
$pre = explode('.',$signed_request); // Get the part of the signed_request we need.
$json = base64_decode($pre['1']); // Base64 Decode signed_request making it JSON again.
$obj = json_decode($json,true); // Split the JSON into arrays.
$app_data = json_decode($obj['app_data'],true); // Get out just the app_data part
$variable1 = $app_data['variable']; // Pull out the value attached to our first variable in the array and set it to something for later use.
$otherparameter = $app_data['parameter name']; //And so on..
[/PHP]

Now, if I was you, I would make your page tab content some script that has all this in there and in the body echoes the variables so you can create an advert > preview > test it is working, play around etc. If I recall rightly FB also gives your page tab access to a small amount of user data like gender?, age range and country. You should be able to see these if you just echo the entire $signed_request or $app_data, bleh I dunno one of those. Anyway these may come in handy, useful when people come not via adverts so you can at least get some info.

To do this you can decode everything then use if(isset($variable)) to check if someone has some value you passed via app_data, and if they don't, you just set everything differently.

[PHP]
$pre = explode('.',$signed_request);
$json = base64_decode($pre['1']);
$obj = json_decode($json,true);
$app_data = json_decode($obj['app_data'],true);
$user = $obj['user']; //array of some user data
$age0 = $user['age']; //ignore
$age = $age0['min']; //age range methinks
$country = $user['country'];
[/PHP]

Can't remember how you get gender. This is getting way too long winded and I'm soon to leave LAX so I will call it quits here. Enjoy playing with PHP.
Hey zeno, i got side tracked forgot to thank you for this, it was just what I was looking for.


11-26-2012 10:01 PM #6 hd2010 (Member)

zeno is so hardcore with his php skills


11-27-2012 01:11 PM #7 caleb (Senior Member)

I'm in awe. wow.


12-02-2012 11:03 PM #8 nissangtr (Member)

I'm using "Static Iframe Tab" for my FB page - will this code work with it or do I need to create a page tab using some other method?


12-02-2012 11:31 PM #9 rockstar john (Member)

Quote Originally Posted by partner View Post
Ok So here's the setup

Sending FB ads to Page tab
Trying to track 1 extra variable ( ad id, demo etc )
Tracking platform cpvlab


Can it be done? Can I pass one extra variable? Old thread I found from 2011 says it cannot, has it changed in a year, seems with sponsored story it can by adding url values, but am looking for regular ad.

Possible?
Zeno has answered your question, clearly, sick programming skills!

lol just had this same issue last week.

The answer is yes of course its possible.

I took the easy route and just put the link directly into the ads.
The app tab thing is not required dear boob.


12-03-2012 12:43 AM #10 zeno (Administrator)

Quote Originally Posted by nissangtr View Post
I'm using "Static Iframe Tab" for my FB page - will this code work with it or do I need to create a page tab using some other method?
Not sure if there are any issues there, if the app just loads another pages content in the canvas then it should work. I like to use my own page tab apps rather than involving something else. Just try it out and echo some stuff in the page.


12-03-2012 01:20 AM #11 nissangtr (Member)

@zeno, thanks - I did try putting some php code into the "Static Iframe Tab", but saw no output.

Anyone have a tutorial on creating a page tab app? Just want to be able to have a page tab that can support PHP code.


12-03-2012 01:49 AM #12 zeno (Administrator)

Making page tabs is easy as! As for containing PHP code, you just point them directly at whatever URL you want. To make a page tab app you do this:

1. Go to https://developers.facebook.com/apps
2. Click "Create New App"
3. App name whatever you want, leave namespace blank and hosting option unticked -> click continue.
4. It will take you to your app config page where you can change things. Click the [TICK] Page Tab box section at the bottom of the page.
5. Fill out a page tab name (will show as tab name on your page)
6. Put in the URL of the page you want to load in the tab canvas and the same in the secure URL but obviously with https instead of http.
7. Make sure tab width is on normal (810 px). SAVE CHANGES. You can change the tab images later. The page tab image shows on your main page underneath the cover image and is 111x74. The main tab icon up the top is 75x75 and the small icons (can see these in your apps list) are 16x16. Lets add that page tab app to your page!

8. Copy and paste this into your address bar:

Code:
https://www.facebook.com/dialog/pagetab?app_id=IDHERE&next=PAGEURL
For the app_id part you want the appid of that page tab app you just made, up the top by the app name and app secret. For page URL, copy and paste in the Page Tab URL that you put in the section at the bottom. Click go, it should now ask you what pages you want to add the page app to. Done, that's it. The slowest part of this whole process is copying and pasting in the appid and page url.


12-03-2012 01:59 AM #13 doryphoros (Member)

Damn son, you sure you're not getting your PhD in computer engineering?


01-27-2013 11:05 PM #14 nissangtr (Member)

I followed Zeno's easy-to-follow page tab creation steps - does anyone know if it is possible to extract and then echo out the user's age, gender, etc?


01-27-2013 11:26 PM #15 zeno (Administrator)

Some of that info is in the signed request FB passes through to the tabs. Use
[PHP]
$pre = explode('.',$signed_request);
$json = base64_decode($pre['1']);
$obj = json_decode($json,true);
$app_data = json_decode($obj['app_data'],true);
echo $app_data
[/PHP]

You should be able to find that info inside the app_data array of information, then you just extract it out.


01-28-2013 05:29 AM #16 nissangtr (Member)

Hi Zeno,

Thanks for the code - I tried but the $app_data is empty if I click on the page tab directly. If I come from one of my adverts (http://www.facebook.com/pages/pagename/123456789012345?sk=app_PAGE_APP_ID&app_data={"vari able1":"value1"}), the echo $app_data just displays "Array".


01-28-2013 07:42 AM #17 zeno (Administrator)

Oh, my bad. Should've thought this one through more. Try printing out the $obj array, I think that contains all the interesting data whereas app_data is just what you pass specifically. Use var_dump($obj).


01-28-2013 08:02 PM #18 nissangtr (Member)

Hi Zeno, thanks, that worked - I was trying to echo $obj but was also just getting "Array". The var_dump($obj) does contain some interesting info. Thank you again.


03-17-2013 08:20 AM #19 sutarjo (Member)

Hi Zeno,

Instead of an app advert in Facebook, can we paste those php code into a external url, or Landing Page (http://www.mydomain.com/index.php) and still get those JSON string from Facebook? and pass on to a redirect.php to Prosper 202 for tracking?

Sutarjo


03-17-2013 09:36 AM #20 zeno (Administrator)

Yes, you can use an external ad. The URL will just have to look something like this:

Code:
http://www.facebook.com/pages/something/1234567890?sk=app_1234567890&app_data={"subid1":"XX","subid2":"YY"}
Also note that I think the mechanism to add page tabs has change, the new link is this one:

https://www.facebook.com/add.php?api_key=APIKEY&pages=1

Where APIKEY is that supplied by your pagetab app.


Home > Paid Traffic Sources > Facebook & Instagram