1
votes

Has anyone been able to get the Enhanced Link Attribution feature working with Universal Analytics implemented via Google Tag Manager?

My client's website has multiple links with onclick events rather than unique href values, and we'd like to be able to view and differentiate between them in the In-Page Analytics reports. I've successfully been able to differentiate between these clicks within other report views by passing an eventLabel via the datalayer, but for some reason, the In-Page Analytics do not differentiate between these links.

I've enabled Enhanced Link Attribution within my Universal Analytics tag in Tag Manager, and I've also enabled Enhanced Link Attribution within the Analytics Admin settings per https://support.google.com/analytics/answer/2558867.

I have also assigned a unique id value to each of these links, but they are still not differentiated in the In-Page Analytics view.

For example, here is an example of the markup for each of these links:

<a id="video_nIDJiWBSKa8" onclick="OpenVideo( 'nIDJiWBSKa8' );dataLayer.push({'eventCategory' : 'videos', 'eventAction' : 'open', 'eventLabel' : 'Tutorial Video', 'event' : 'shadowboxVideo'});return false;" href="#">Tutorial</a>

I have also tried to give each link a unique href value (#video_nIDJiWBSKa8) rather than just the "#", but this had no effect either.

Am I missing something? I've been looking for a solution for weeks... does anyone have any ideas or suggestions?

Thanks in advance for any help!

2
I have no source beside what I tested myself, but I don't think enhanced link attribution recognizes a click event; as far as I can tell it requires that you actually follow the href. - Eike Pierstorff
Thanks Eike. According to the documentation (support.google.com/analytics/answer/2558867?hl=en), it should recognize the click if I assign a unique ID value (which I've done). The element does have an HREF="#" value as well, but maybe that's the problem. I tried adding unique href values to each link as well (href="#video_nIDJiWBSKa8"), but that didn't seem to work either. The lack of documentation from Google (especially in regard to Tag Manager) makes this very tough to troubleshoot. - bednarmultimedia

2 Answers

1
votes

Linkid works by capturing click events that bubble up to the body element. You have a "return false" that prevents that event from bubbling up so linkid is not aware that you have clicked somewhere.

What you probably want there is an "event.preventDefault();" rather than a "return false;

PS: You might want to take a look at this article for a more in-depth explanation about why "return false;" is probably not what you want 99 out of 100 times. http://fuelyourcoding.com/jquery-events-stop-misusing-return-false/

1
votes

In a Google product forum discussion, it is suggested that In-Page Analytics will only work if the clicks are tracked as page views:

https://productforums.google.com/forum/#!topic/analytics/B3gbAJEdp1w

Thus, you would need to track the clicks as virtual page views instead of events. There is a tutorial for tracking virtual page views with tag manager here:

http://www.lunametrics.com/blog/2014/09/10/fire-virtual-pageview-google-tag-manager/

Virtual pageviews through tag manager are also briefly covered in the Google Analytics documentation:

https://developers.google.com/analytics/devguides/collection/upgrade/reference/gtm#virtual

Obviously, the virtual URL tracked as a page view for a particular link would have to be identical to the value of the href attribute of the same link. As Google Analytics does not send the anchor part of the link (after #) to the server, the unique part of the href value / virtual URL must come before the #. (In fact, no # part is needed.) Since the default click action will be prevented, this should not be a problem.

Finally, as suggested in another answer, it might be best to use preventDefault() instead of return false, as otherwise enhanced link attribution will not come into effect. But if the virtual URLs are unique in themselves, enhanced link attribution should not be needed in the first place, so using preventDefault() instead of return false would only be an extra precaution.