How to set up cross-domain tracking with GTM in Unbounce


Badge +1
  • Technical Support Specialist @ Unbounce
  • 6 replies

In this example, I’m setting up cross-domain tracking from https://anna.ubpages.com/gtm-cross-domain-tracking-orig/ to https://anna-test.support-test.ca/gtm-cross-domain-dest/.

 

The steps are based on this guide:

Note: this process is for Universal Analytics (UA) Google properties.


In addition to the steps from the guide linked above, it's also necessary to add the script that removes clkn/clkg wrappers from the links on Unbounce pages because the wrappers prevent Google from being able to append the linker parameter (the script should be added before doing any of the Google-specific steps). The script is the following:

<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>


<script> $(function($) {
$('a[href]').each(function(){
$(this).attr('href',
$(this).attr('href')

.replace(/.+?(?=(clk(n|g)\/https\/))/, '')
.replace(/.+?(?=(clk(n|g)\/http\/))/, '')

.replace(/clk(n|g)\/https\//, 'https://')
.replace(/clk(n|g)\/http\//, 'http://')
.replace(/clk(n|g)\/tel\//, 'tel:'));
});
});
</script>

Important: this script prevents conversions from being tracked in Unbounce. Once the script is added, no conversions will be recorded (leads are still recorded). We do have a variation of this script that allows for conversion tracking but it has to be customized for each specific button (the one I included above works for any page and button). Since it requires customization for each page and button, it’s recommended to have some basic coding skills to use that version. If you’re interested, please reach out to api-team@unbounce.com and mention this post.

In terms of the Google-specific setup, here are the steps (in the guide, the steps are starting with Part #2.4):

A quick note — for my test page where I set up cross-domain tracking from https://anna.ubpages.com/gtm-cross-domain-tracking-orig/ to https://anna-test.support-test.ca/gtm-cross-domain-dest/, both of the domains are in the same GTM container. According to the guide, it's also okay if the domains are in different GTM containers. The only requirement here is that the Google Analytics property is the same.

1. Set up the Auto Link domains option with GTM (Part #2.5.2 in the guide): https://www.screencast.com/t/13uoC5QTUL3 by adjusting the variable settings.

After completing the variable setup, it's best to verify that Google appends the linker parameter to the outgoing URL. The destination URL will look like this once clicked:
?name=inline-194954166.png

2. Part #2.6 from the guide. Since both of my domains are in the same GTM container, I added the allowLinker field to the same variable where I added the Auto Link option (see the variable setup screenshot above).

3. Part #2.7 from the guide. I updated the referral exclusion list in the Google Analytics property to include the destination domain anna.ubpages.comhttps://www.screencast.com/t/fXTel9SPW4i.

 


0 replies

Be the first to reply!

Reply