Skip to content

Instantly share code, notes, and snippets.

@webhasan
Last active November 8, 2023 08:16
Show Gist options
  • Save webhasan/a1d968862ce47498b8baf572eb19d7a9 to your computer and use it in GitHub Desktop.
Save webhasan/a1d968862ce47498b8baf572eb19d7a9 to your computer and use it in GitHub Desktop.
Affiliate Link Tracking with GTM Code
// example affiliate link
// https://leocoder-shop.myshopify.com?affiliate_id=rubel
// set affiliate id
var queryParts = new URLSearchParams(window.location.search);
var affiliate_id = queryParts.get('affiliate_id');
if(affiliate_id) {
localStorage.setItem('affiliateId', affiliate_id);
}
// collect affliate id
localStorage.getItem('affiliateId');
// remove affiliate id
localStorage.removeItem('affiliateId');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment