Skip to content

Instantly share code, notes, and snippets.

@johnnyopao
Last active December 15, 2022 11:43
Show Gist options
  • Save johnnyopao/a69b41357ccafe10dae8 to your computer and use it in GitHub Desktop.
Save johnnyopao/a69b41357ccafe10dae8 to your computer and use it in GitHub Desktop.
GA Cross domain: Carry Analytics ClientID across domains

GA Cross domain tracking: Carry over Analytics ClientID across domains

Google Analytics

This code is used to track users in GA across two completely different root domains (A.com to B.com). Insert the code below into your Unbounce landing page.

<script>
  $('.lp-pom-button, .lp-pom-text a, .lp-pom-image a').click(function(event) {
    var parentClass = $(this).parent().attr('class');
    
    var isFormRedirect =
      parentClass === 'lp-element lp-pom-form' &&
      window.module.lp.form.data.confirmAction === 'url' &&
      lp.jQuery('form').valid() === true;

    if (isFormRedirect) {
      ga(function(tracker) {
        var linker = new window.gaplugins.Linker(tracker);
        window.module.lp.form.data.confirmData = linker.decorate(window.module.lp.form.data.confirmData);
      });
    } else {
      ga('linker:decorate', this);
    }
  });
</script>

Google Tag Manager

Follow the article below. See section "Clicks from A.com to B.com (Auto Event Tracking)" https://support.google.com/tagmanager/answer/3561401?hl=en#StepsClicksAutoEventTracking

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment