Passing Facebook parameters in URL

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 :slight_smile:

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!

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