Passing Facebook parameters in URL

  • 27 May 2020
  • 3 replies
  • 219 views

Hi guys,

I’m currently using a few landingpages outside Unbounce but I’m trying to get this code working within Unbounce so we can also move these pages since the Unbounce builder is a way better way to work on these pages 🙂

We have this bit of code:

function clickout() {
window._fbq.push('track', 'InitiateCheckout');

var element = event.srcElement;
var fbc = getCookie("_fbc");
var fbp = getCookie("_fbp");
if (fbc == null || fbc == "") {
var urlParams = new URLSearchParams(window.location.search);
fbc = urlParams.get('fbclid');
}
element.href = element.href + "&afid=" + fbc + "&afid_2=" + fbp;
}

Is it possible to give a button on Unbounce the clickout function? We now use links and add this in the a href code at the end: onclick=“clickout();” and then it works. In Unbounce you can’t edit that source so how can I get this working?

Also will Unbounce allow the javascript to modify the URL and add the 2 extra values?

Thanks!


3 replies

Userlevel 7
Badge +3

Hi @remziej,

Is it possible - yes.

It would be a bit more complicated than the script your are currently using.

There are essentially 4 things happening in your current script:

  1. Custom event for the Facebook pixel
  2. Getting 2 Facebook cookies
  3. Getting the fbclid parameter that Facebook attaches to outgoing links
  4. the afid & afid2 - I assume those are affiliate IDs and they would be appended to the URL or do you need to grab them from somewhere?

Regarding items 3 & 4 from above you’ll need to write a function that would getUrlParameter, split and splice the individual parameters (removing the &).

After that append it to a button.

Item 2 regarding cookies might be a bit more complicated due to browser security. Depends on how the cookie is set and if you can read it.

Item 1 should be pretty straight forward to execute onClick of the button(s).

Hope this points you in the right direction.

Best,
Hristian

Badge

How do we capture the fbp id and pass it out the backend via the pixel?

Hey there
Have you looked into google tag manager? Most functions you mentioned can be activated through GTM, but they require some coding.

Otherwise, If you’re looking for a no code solution that does everything you mentioned out for the box, I would recommend trying out anytrack.io.

It is integrated with both Facebook CAPI, fb pixel as well as over 100 affiliate networks.

Let me know if you have any questions
Laurent

Reply