Advertisement
briank

Remove Kartra analytics URL parameters

Aug 4th, 2024
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 0.77 KB | None | 0 0
  1. <script>
  2. /*
  3.  * Remove Kartra analytics tracking parameters from link URLs.
  4.  * Breaks Kartra tracking, but may be required if other software breaks.
  5.  * For Kartra pages, add to body tracking.
  6.  */
  7. function untrackLinks () {
  8.     for (const link of document.querySelectorAll('a[href*="kref"]')) {
  9.     const url = new URL(link.href), sp = url.searchParams;
  10.     sp.delete('kref');
  11.     sp.delete('kuid');
  12.     url.search = sp.toString();
  13.     link.href = url.toString();
  14.     }
  15. }
  16. untrackLinks();
  17. (() => {
  18.     const mo = new MutationObserver(mrs => {
  19.     for (const mr of mrs) {
  20.         if (mr.attributeName) {
  21.         untrackLinks();
  22.         return;
  23.         }
  24.     }
  25.     });
  26.     mo.observe(document.body, {
  27.     subtree: true, childList: true, attributes: true,
  28.     attributeFilter: [ 'href' ]
  29.     });
  30. })();
  31. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement