Skip to content

Instantly share code, notes, and snippets.

@atikju
Created July 18, 2021 04:39
Show Gist options
  • Save atikju/3b86e77ff49645c9c6b3b4b0c5e5ef53 to your computer and use it in GitHub Desktop.
Save atikju/3b86e77ff49645c9c6b3b4b0c5e5ef53 to your computer and use it in GitHub Desktop.
if (window.location.search != '') {
var fb_campaign_id = '';
var search_items = window.location.search;
search_items = search_items.replace('?', '');
search_items = search_items.split('&&');
for(i=0;i<search_items.length;i++){
var thisItem = search_items[i];
if(thisItem.indexOf('utm_medium') > -1){
var getCampaign = thisItem.split("=");
fb_campaign_id = getCampaign[1];
var buyLinkList = document.getElementsByClassName('buyBtn');
for(i=0;i<buyLinkList.length;i++){
var newURL = buyLinkList[i].href+'?attributes[fb_campaign_id]='+fb_campaign_id;
buyLinkList[i].href=newURL;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment