0

I'm trying to count clicks on links leaving my site. For example, I have to count clicks on this link http://portal.adp.com/public/index.htm and I'm working from documentation at Tag Manager Help > Google Analytics Events

Step 3 under Clicks on Links doesn't match the actual user interface in Google Tag Manager.

3. For each link, add a Google Analytics event tracking tag and set the
firing condition to the ‘Buy Clicks’ trigger configured above. For example:

  a. Tag: Google Analytics
  b. Triggers: Click
      a. Name: Buy Clicks
  c. Tag Name: UA - Event - Buy Link
  d. Tag type: Universal Analytics
  e. Track Type: Event
      a. Category: Nav
      b. Action: Select
      c. Label: Buy

I'm hoping someone here can clarify for me what the next step is and also review the Enable when condition in my trigger below (3rd screenshot).

This is where I'm stuck in step 3 - creating a new tag and part b setting the trigger for clicks. I don't see any trigger setting option in the following dialog.

enter image description here

From the previous steps 1 and 2, I have the following tag and trigger.

Tag

enter image description here

Trigger

Potential problem: setting my site as referrer may be incorrect. My idea was to capture events where my site refers a link offsite. What should this be?
enter image description here

And, of course, the Tag Manager is already installed on my site.

<!-- Google Tag Manager -->
<noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-WC9CXW"
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-WC9CXW');</script>
<!-- End Google Tag Manager -->

Finally, Google Analytics Help > Track outbound links provides a workaround that requires adding another script to my site and altering the HTML. I understand Tag Manager works in such a way that allows you to avoid altering site or app content. I would like to not use the workaround if possible as I will be tracking many offsite links.

2 Answers 2

1

The easiest way to track outgoing link clicking is by making a variable of type Custom JavaScript. Make sure that you have the two built in variables Click URL and Page Hostname enabled. In the JS variable you can then compare these two.

Basically my script returns true or false by checking:

{{Click URL}}.indexOf({{Page Hostname}}) !== -1

{{Click URL}} == ""

typeof {{Click URL}} == 'undefined'

{{Click URL}}.indexOf('javascript:')

You can then use that variale in the trigger. Enable the trigger on any page with Page URL matches REGEX .* and set the fire when the JavaScript variable equals false.

You need to change the tag though. Currently you are just sending another pageview. What works better is setting it to type Event and then set the Event Category to Outgoing Link and the Label to {{Click URL}} That way you can easily check all the differrent URLs that are being clicked on.

2
  • Google Tag Manager preview gave me this error on that script: JavaScript Compiler Error: Error at line 9, character 4: Parse error. ')' expected
    – Michael
    Commented Apr 29, 2016 at 23:04
  • I'd need to see your code to see where the error is. can you post it? Commented May 2, 2016 at 19:17
0

An easy way is to create an event tag with a link click trigger where the clicked url does not contain your hostname, but watch out for clicks that land in elements without href attributes like for example jumplinks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.