Tracking Link Clicks with Tag Manager Part II: Examples

Posted in Search & Social — Dec 18, 2014

In Part I, we explained the basics of setting up link click tracking in Google Tag Manager. In Part II, we go into some specific examples.

UNIVERSAL ELEMENTS OF A LINK CLICK TAG

Let's first clarify the following universal elements:

universal link click elements

  1. *Tag Name: * Give the tag a name that makes sense to you.
  2. *Tag Type: * Select either "Universal Analytics" or "Classic Analytics", depending on whichever you are using.
  3. Tracking ID You can either manually type your unique Google Analytics ID into this field (ex: UA-########-1) or use a convenient macro that plugs this in for you.
  4. *Track Type: * Select "Event" as the tag type.
  5. *Assign Parameters: * Here is where you choose the tag's Category, Action, and Label.
  6. Firing Rules: Each tag always starts with a firing rule of Event Equals gtm.linkClick. Additional rules will specify the type of link.

firing rule equals gtm.linkClick

*What changes for each tag? *
Basically, only the Firing Rules, and potentially, the Tag Parameters (category, action, label).

HOW TO TRACK EMAIL LINK CLICKS

Example 1: Track All Clicks on Any Email

Suggested Parameters
naming parameters

  • Category: Email Link Click - I manually named this, so it's easy for me to see that this category includes any link on an email address.
  • *Action: {{url}} *- This is a macro. True to its name, the URL macro plug the URL of the page that the link click occurred on. For example, if someone was on the /about/ page, and clicked on an email address, then Google Analytics will record /about/.
  • Label: {{element url}} - Also a macro, this Element URL macro records the specific link that was clicked on. For example, if the user clicks on "sales@wearefine.com", that's what Google Analytics will record.

Suggested Firing Rules
mail click firing rules

  • Event Equals gtm.linkClick: Always set this for all link click tags.
  • Element URL contains mailto: This is where the firing rules are truly specific to tracking clicks on email addresses. Every single email address links contains mailto: so this firing rule ensures that this tag only fires on clicks where links are "mailto" type email addresses.

Example 2: Tailor Tags for Individual Emails or Pages

Depending on your needs and individual preferences, you may not want to track all emails. Or, you may want to create more in-depth tags that give emails more concise parameter labels. Or - you may only want to track emails on some pages. There are endless variations on this theme, but here are a few ideas and examples:

  • Tracking Emails only on a Certain PageThe parameters can stay the same as the basic tag, but here's how you'd edit the firing rule to be particular to one page:
    track emails on a specific pageFor example, if you want to only track email address clicks on the "about" page, you can add that the {{URL}} {{contains}} about. Depending on the format of the page, you can use a variety of different criteria - or even regular expressions - to isolate a URL or set of URLs.
  • Tracking A Specific AddressFor the tag itself, you can give the tag a unique name and also a unique category name.track a specific email address click
    For firing rules, you can isolate this to the email address itself. In this case, I used a regular expression to match sales/@. There are match types that could work here.
    match regex to tag rules
    TRACKING CLICKS ON PDFS
    Hopefully some of the above examples have helped you see that there's a pretty simple pattern here of intuitively naming parameters and then just adjusting the firing rules for the specific link - or type of link(s) - you want to track. Here's a simple tag and rule that can isolate to a PDF click:
    pdf click tag
    regex matches pdf
    In this general case, the rule is that the regex matches .pdf (remember, when using regex you have to "escape" special characters like periods, etc, with a \ sign} - but you could get even more specific with this to match a specific PDF file name, or only PDFs on a group of particular pages, etc.
    TRACKING CLICKS ON EXTERNAL LINKS (INCL. SOCIAL)
    Example 1: Track All External Links
    As with any tag, the parameters for this are really flexible - one suggestion is to configure as follows:
    tag config all external links
    The firing rule for this tag uses a regular expression to exclude clicks on your own domain: .yourdomain.com. (Obviously, replace "yourdomain" with whatever your actual domain happens to be.)
    exclude your domain
    Example 2: Track Social Media Profile Links
    I personally prefer to narrow down external links certain types of links, such as for social media. Here's one example of how to do that:
    social profile clicks
    Rules to Track all - or just some - Social Media Link Clicks:
    Here, we can track all social media link clicks by using a rule that the element URL matches the regex: .facebook.com.|.twitter.com.|.instagram.com.|.pinterest.com.|.linkedin.com.|.youtube.com.
    track all social media link clicks
    Or, instead of tracking all, you can just track clicks to your own social profiles using a rule of something like this:
    .facebook.com\yourprofilename|.twitter.com\yourprofilename|.instagram.com\yourprofilename
    And so on. The difference is that instead of using a wild card on the end of the social profile (.
    ) that would match anything, you're instead stipulating your own profile name, etc.
    TRACKING SOCIAL MEDIA SHARES **
    Wouldn't social media interactions, like Facebook likes, Pinterest pins, Twitter tweets, etc., also be classified as a gtm.linkClick event?
    Unfortunately, no. In order for social interaction tracking to work, you need to create a new type of social interaction event called socialInt. You'll also likely need the help of a developer to push this event into the data layer:
    Google Tag Manager
    For additional details, please see Simo Ahava's excellent post on how to track social media interactions.
    **TRACKING LINK CLICKS BY ELEMENT CLASS OR DATA ATTRIBUTE

    Sometimes, you will need highly specific rules that isolate a link to a specific attribute. For example, let's say you want a tag that isolates social profile links in the footer only:
    footer link clicks
    If we examine the source code, we can see that these footer social media links have a special, unique class of stalk-icon:
    special link class for footer
    That means that when we create tag firing rules, we can just stipulate that the tag fires when any link matches this element class:
    firing rules match footer class
    For an even cleaner implementation (one that your dev will appreciate), instead of relying on the element class, you can stipulate custom data attributes that make this even easier and less-error prone to manage. For additional information, see Luna Metrics' detailed post on tracking clicks with custom data attributes.

Written by Sarah Mackenzie.

More Search & Social