Analytics
6.2K members online now
6.2K members online now
Dive into multiple domain (Cross/Sub) tracking, implementing Ecommerce and Enhanced Ecommerce, setting up Event tracking, and Universal Analytics code.
 
Guide Me
star_border
Reply

Customizing enhanced link attribution dom depth in GTM

Follower ✭ ✭ ☆
# 1
Follower ✭ ✭ ☆

Hi, as stated here:

https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-link-attribution 

You can customize how far up the DOM the plug-in will look for an element ID, as well as the behavior of this cookie, by providing configuration options when loading the plug-in.

 

So I like to use this within Google tag manager

 

ga('require', 'linkid', {'levels': 5});

 

Unfortunately there is only 1 checkbox to get enhanced link attribution on board. Any way to add the extra code? What is the level of dom it looks in by default? 

Re: Customizing enhanced link attribution dom depth in GTM

Follower ✭ ✭ ☆
# 2
Follower ✭ ✭ ☆

Hi Keesjan

Please try following code to implement HTML Custome Tag in Google Tag Manager on every page.
I think that it will surely work.

 

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'REPLACE YOUR TRACKING ID', 'auto');
ga('require', 'linkid', { 'levels': 5 });

// Don't Send Pageviews.
</script>

 

Customizing enhanced link attribution dom depth in GTM

[ Edited ]
Follower ✭ ✭ ☆
# 3
Follower ✭ ✭ ☆

Hi Yamada, thanks for your solution, definitely try it out.

Next to this GTM  Custom Tag script

in the normal GTM universal analytics script I should uncheck the 'extended linkattribution' to not load linkid twice?

About that last one: what is the default dom-level it is looking for?

 

Should I not worry about loading the 'https://www.google-analytics.com/analytics.js' script twice (ones in deafault universal analytics GTM tga and ones more in the costum script?

Any pitfalls on ordering the 2 scripts. What should load first

 

And any idea why link clicks on subdomain 1 to subdomain 2 are not shown in the chrome extension? I searched around and a lot of peoplehave this issue.

 

 

Re: Customizing enhanced link attribution dom depth in GTM

Follower ✭ ✭ ☆
# 4
Follower ✭ ✭ ☆

Hi Keesjan

 

I created a test site and tried it.
As a result, that UA Pageivew tag required the following configuration.

  • "Enable Enhanced Link Attribusion" is False
  • Set Tracker Name" is Checked but Tracker Name is blank
  • Fire a tag before UA tag fires "UA Setup" Tag(Custom HTML)

 

Capture_20170111_2225.png

 

 

UA Setup Tag is my first reply.

 

About that last one: what is the default dom-level it is looking for?

Default dom-level is 3. It is described int the URL below.

https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-link-attribution?h...

 

Should I not worry about loading the 'https://www.google-analytics.com/analytics.js' script twice (ones in deafault universal analytics GTM tga and ones more in the costum script?
Any pitfalls on ordering the 2 scripts. What should load first

It reads analytics.js twice, but it does not affect the operation.
If you are concerned, please use the following tags for UA Setup Tag.

 

<script>
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga('create', 'UA-999999-99', 'auto');
ga('require', 'linkid', { levels: 5 });
// Don't Send Pageviews.
</script>

 

And any idea why link clicks on subdomain 1 to subdomain 2 are not shown in the chrome extension? I searched around and a lot of peoplehave this issue.

If domain1 and domain2 have the same property ID, I think that it will be sent.

Re: Customizing enhanced link attribution dom depth in GTM

Follower ✭ ✭ ☆
# 5
Follower ✭ ✭ ☆

Hi Yamada,

thanks for your great help sofar.

so the "UA Setup" Tag(Custom HTML) must fire before the normal GA tag?

 

Any idea what the cooky duration and name do when added to the linkid?

 

ga('require', 'linkid', {
  'cookieName': '_ela',
  'duration': 45,
  'levels': 5
});

 

About cross-subdomain measurement.

can it has to do we used the new GTM placement on subdomain 1 and the old one on subdomain2?

 

new: https://developers.google.com/tag-manager/quickstart

  1. Copy the following JavaScript and paste it as close to the opening <head> tag as possible on every page of your website, replacing GTM-XXXX with your container ID:
     
    <!-- Google Tag Manager -->
    <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
    new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
    j
    =d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
    'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
    })(window,document,'script','dataLayer','GTM-XXXX');</script>
    <!-- End Google Tag Manager -->
  2. Copy the following snippet and paste it immediately after the opening <body> tag on every page of your website, replacing GTM-XXXX with your container ID:
     
    <!-- Google Tag Manager (noscript) -->
    <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXX"
    height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
    <!-- End Google Tag Manager (noscript) -->

In the old style there is only GTM script in de <body> section like:

<!-- Google Tag Manager -->
<noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-xxxxxx"
height="0" width="0" 
style="display:none;visibility:hidden"></iframe></noscript>
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src='//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-xxxxxx');</script>
<!-- End Google Tag Manager -->

 

Customizing enhanced link attribution dom depth in GTM

Follower ✭ ✭ ☆
# 6
Follower ✭ ✭ ☆

Hi Keesjan

 

As long as I tested, I need to send UA Setup Tag followed by UA Pageview Tag.

Enhanced link attribution is working such as following.

1. When the link is clicked, the link ID is saved in the cookie.
2. If the link ID is stored in the cookie, the link ID is also sended at the time of pageviews.

caution: The link ID specified the ID by tracing only the level specified by "levels" option(default levels is 3).

CookieName and duration option are store cookie configuration. default cookieName is "_gali", default duration is 30 second.
Enhanced link attribution can only be applied to internal links, so duration should be as long as 30 seconds.


The place of installation of GTM does not matter this time.

Customizing enhanced link attribution dom depth in GTM

Follower ✭ ✭ ☆
# 7
Follower ✭ ✭ ☆

Hi Yamada,

yes when I re-read your setup its clear that first GA must be loaded and then as second the linkid script. Thank you.

 

Sorry, I still don't understand the value of cooky duration. 

Example: if the cookie is set to 'duration': 600 (10 minutes) what will it do better or worse?

"Enhanced link attribution can only be applied to internal links, so duration should be as long as 30 seconds."

as long as 30 seconds. but why not 10 or 60?

 

Cannot understand the impact of this duration. Hope you can shed some light on it.

ps: I installed chrome Cooky inspector and I see that sometimes the default  cooky i set and sometimes not for internal link clicks. Has the duration to do with this? 2 kliks within 30 seconds count as one?

 

 

Customizing enhanced link attribution dom depth in GTM

Follower ✭ ✭ ☆
# 8
Follower ✭ ✭ ☆

Hi

 

Cookie duretion means that the cookie value expires.

If the time from clicking the link to loading the next page exceeds 30 secondes(such as configured by duration), the cookie value are deleted and it will be over there.