Skip to content

Instantly share code, notes, and snippets.

@transcendr
Created December 21, 2023 19:52
Show Gist options
  • Save transcendr/f13f4fe26bfab1a2e94db6088e0bb1da to your computer and use it in GitHub Desktop.
Save transcendr/f13f4fe26bfab1a2e94db6088e0bb1da to your computer and use it in GitHub Desktop.
(()=>{"use strict";!function(){var t,e,n,a,r,o="true"===window.localStorage.getItem("DEBUG"),c=u("partnerId",function(){var t=new URLSearchParams(window.location.search).get("partner");if(t)return t;return window.location.pathname.split("/").pop()||"unknown-partner"}()),i=u("clientRefId","".concat(c,":").concat(Math.random().toString(36).substring(2,15))),s=["reflection.app.link","reflection.test-app.link","buy.stripe.com","stripe.com"];function u(t,e){return m(t)||m(t,e)}function m(t,e){var n;return e&&(document.cookie="".concat(t,"=").concat(e,";path=/")),null===(n=document.cookie.split("; ").find((function(e){return e.startsWith("".concat(t,"="))})))||void 0===n?void 0:n.split("=")[1]}t=new URLSearchParams(window.location.search).get("utm_campaign"),e=new URLSearchParams(window.location.search).get("utm_content"),n=new URLSearchParams(window.location.search).get("utm_term"),a=new URLSearchParams(window.location.search).get("utm_source"),r=new URLSearchParams(window.location.search).get("utm_medium"),document.querySelectorAll("a").forEach((function(u){var m,l=new URL(u.href);if(s.includes(l.hostname)){var d=new URLSearchParams(l.search);d.set("affiliate_id",c),d.set("client_reference_id",i),d.set("utm_source",a||c),d.set("utm_medium",r||"partner"),d.set("utm_term",n||i),e&&d.set("utm_content",e),t&&d.set("utm_campaign",t),l.search=d.toString(),u.href=l.toString()}if(o){var w=null===(m=u.href.split("://"))||void 0===m?void 0:m[1];w&&console.log("Augmented link","".concat(w))}}))}()})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment