Cool stuff with lookup tables in Google Tag Manager

Last updated on Jul 14, 2015

Lookup tables are one of the most useful and powerful features of Google Tag Manager when it comes to customising and improving your Google Analytics tracking configuration. In this article, you will find answers to the following questions:

  • What are GTM lookup tables?
  • How can I track my traffic sources correctly with the help of GTM lookup tables?
  • How can I track clicks on social icons with GTM lookup tables?
  • How can I reduce the number of tags I need using GTM lookup tables?

If you have any additional questions or if anything remains unclear, please don’t hesitate to leave a comment at the bottom of this page. I normally reply within a couple of days.

So, let’s get started and have a look at some of the cool stuff you can do with lookup tables in Google Tag Manager.

What are lookup tables?

A lookup table in Google Tag Manager is a variable that has the value of another variable as input. Variables, according to Google’s definition, are “name-value pairs for which the value is populated during runtime”.

Google Tag Manager has a number of built-in variables, such as “Page URL”, “Page Path”, or “Page Hostname”. The output value of the variable “Page URL” is the URL of the current page, so on this page it would be “”. The value of the variable “Page Hostname” is the hostname of the current page, so for this page it would be “”. The variable “Page Path” is the part of the “Page URL” that comes after the “Page Hostname”, so on this page it would be “/lookup-tables-google-tag-manager/”.

You can check the output values of all the active variables on your own website by activating the GTM preview mode and going to “Variables”. For the current page, the values of the variables mentioned above are shown like this:


On top of the built-in variables, Tag Manager allows you to define your own set of variables. Lookup tables are a type of user-defined variables and they can be very helpful when you use them in triggers (formerly known as rules), but also when you use them in tags to populate certain fields with dynamic values. Later on in this article, we will have a look at some of the possibilities lookup tables give you.

As mentioned above, lookup tables are a type of variable that have the output value of another variable as input. To get back to our “Page URL” example, I could use the output of this variable as input for a new lookup table variable that I define myself. Remember that the output of the “Page URL” variable always is the URL of the current page. In a lookup table, you always define pairs of values: If the input equals “xyz”, I want the output to be “123”. If the input equals “abc”, I want the output to be “789”, and so on.

If, for some reason, I wanted to track, let’s say, the mood I was in when I published my blog articles, I could use a lookup table to define a mood value output for every URL input and send the values to Google Analytics in a custom dimension. So if the output of the variable “Page URL” was “”, I could use a lookup table that defines the value “grumpy” for this pageview and send it to Google Analytics.

Here’s what this lookup table would look like in GTM:


I could now use the output value of this lookup table to populate a custom dimension in a Google Analytics page view tag. But let’s just have a look at some real-life examples of lookup tables that actually make sense 😉

Use a lookup table to track different traffic sources

The first time I came in contact with lookup tables was after reading this brilliant article on the LunaMetrics blog. Jim Gianoglio describes how you can use URL fragments to track different traffic sources in Google Analytics using a lookup table. I love this solution and I have been using it in a slightly modified way on all of my clients’ websites and also here on ever since.

I will quickly walk you through setting this up in Google Tag Manager (V2). The goal of this solution is to be able to track the traffic your social posts and other traffic sources generate without having to use Google’s UTM tracking parameters (the horrible ones that look like this: “?utm_source=facebook&utm_medium=social&utm_campaign=facebook-posts”).

First, you need to set up a user defined variable of the type “URL”. In the configuration of the variable, select the component type “Fragment”. Make sure you give the variable a clear name that you will remember and recognise, like “URL fragment”. This variable will now have the URL fragment of the current page as output. Here’s what it looks like in GTM:


A URL fragment is the part of the URL that comes after the hash (#), if there is one. So now your Tag Manager configuration is able to read the URL fragments of URLs like this:

  • and so on


Do you see where this is heading? You can now tag the links you share on social media or in your newsletter in a much easier and more user-friendly way than with UTM tracking parameters. Next, let’s see how to get this data into Google Analytics.

So why don’t we just send the value of the “URL fragment” variable straight to Google Analytics? Because URL fragments are used for plenty of purposes and we only want to send the values we defined for our different marketing channels to Google Analytics. This is where the lookup table comes in handy: It acts as a kind of filter.

So the next step is to create a variable of the type “Lookup Table” and choose our recently created new variable “URL fragment” as input value. Now we have to define the rows of the table, so for every channel or network we want to track, we need to define an input-output pair. Note that, even if the input and output are exactly the same, this makes complete sense. The lookup table is acting as a filter here so that you have complete control over the possible outputs of this new variable. The lookup tables that I use for this purpose often look like this:


And we’re almost done! Now you can use your new lookup table to populate a custom dimension in your Universal Analytics tag and send the data to Google Analytics. I will soon dedicate an entire post to tracking traffic sources correctly and analysing the data in Google Analytics. Let’s now move on to more cool stuff you can do with lookup tables in Google Tag Manager.

Use a lookup table to track clicks on social icons

Another very interesting way to use lookup tables is for the tracking of outbound links. For the social profiles that you link to from your website, you can create a lookup table that defines a descriptive output value for each of the URLs you link to, for example “facebook profile”, “google+ profile”, and so on.

You can now use the output of this lookup table as a condition in a link click trigger and at the same time to populate the values of the events you send to Google Analytics. Here are the steps you need to undertake:

  • Create a lookup table that gives a descriptive name to the URLs of the outbound links you want to track. Use the URLs of your social profiles as inputs and the descriptive names as outputs.
  • lookup-table-for-social-profile-URLs

  • Create a new trigger with the event type “click”.
  • Choose the type “link click”.
  • Select “Fire on some clicks”, select the name of your new lookup table, and set the condition that it match a regular expression with all the output values of your lookup table, separated by vertical bars, for example: googleplus|linkedin|twitter
  • social-profile-click-trigger-GTM

  • Create a new Universal Analytics Tag and select the track type “event”.
  • Use your new lookup table to populate the fields you send to Google Analytics. It makes sense to use the output value in the field “Label” under “Event tracking parameters”.
  • Profile-click-event-tag-settings

  • In the last step of your Google Analytics tag configuration, select “fire on click” and pick your newly created link click trigger.
  • Fire-GTM-tag-on-click-event

This is so easy that it feels like cheating! But we’re already done. Your outbound link clicks are now being tracked in Google Analytics and the data even looks nice because you used a lookup table to set descriptive names.

Use lookup tables to reduce the number of tags you need

If you tried to set up the above described solution without lookup tables, you would succeed, but you would need a hell of a lot of tags. So lookup tables help you reduce the number of tags in this case and they do so in many other cases.

You might be using a tag manager container for severel domains. Think about using a lookup table that defines an Analytics tracking ID output for a hostname input. This way you could use one Google Analytics tag to track data in several properties.

Also, with the right combination of lookup tables, you will not need different tags of the same track type any more. One pageview tag, one event tag, one transaction tag (and so on), will be enough in many cases. This makes your Tag Manager account look a lot tidier and it leaves less room for stupid mistakes.

Once you start working with lookup tables you will realise how much time they save you and also how much fun it is to quickly set up things that would have taken an hour before.

Did you enjoy reading this article? Say thanks by sharing it:


  1. Scott Clark
    16. March 2018

    Excellent article. Have you ever seen lookup tables used to do things like swap out Google Adwords conversion tracking scripts or perhaps call tracking scripts? Some of these reside in the head and some in the body of the associated pages. I’m looking at improving efficiency for managing multi-location franchise landing pages and sites.

    • Eoghan Henn
      20. March 2018

      Hi Scott! Thanks for your comment. I’m happy you liked the article. I haven’t seen lookup tables being used for Google AdWords conversion or call tracking scripts, but it sounds like a good idea. I guess you could use lookup tables to match URLs with tracking IDs or conversion labels, in order to reduce the number of tags you need. Let me know how this goes for you if you decide to set it up and feel free to get in touch if you have any further questions.

  2. Laura
    26. July 2017

    Really useful post. I plan to start implementing this right away 🙂 Can we use a tracking hashtag at the end of a PDF link, and it will still work the same? For example, use the following URL https://www.mywebsite/wp-content/uploads/2016/01/blog.pdf#cd122 That way I can track how people accessed the PDF.

    • Eoghan Henn
      29. July 2017

      Hi Laura,

      Thanks a lot for your comment. I’m glad you liked the post.

      I’m afraid the URL fragment tracking method won’t work like that with PDFs. PDF files don’t normally have the Google Tag Manager code, so the Google Analytics tracking code doesn’t fire on them either. There are however ways of tracking PDF views as page views in Google Analytics. Attention: Most guides you find when you search for this only explain how to track clicks on internal links to PDFs, but this will not help you in your case. You will need a solution like this one explained by LunaMetrics:

      Once you’ve set this up, you can probably combine it with a URL fragment solution, but it will be a very different setup from the GTM solution described above.

      I hope this helps! Please let me know if you have any further questions.

  3. Amir
    22. September 2016


    Any idea how i can upload multiple rows at once to a lookup table?
    I tried the method explained in the LunaMetrics blog ( but it doesn’t work for me.


    • Eoghan Henn
      27. September 2016

      Hey Amir,

      Have you seen the update from September 2016 in the article you linked to? Apparently the sheet wasn’t working for a while but now it’s fixed. Maybe this solves your problem already?

      Also, check out the article on the Seer Interactive blog they refer to ( Very useful!

      Let me know if there is anything else I can do for you!


  4. GTM Match Table Generator (Lookup Tables & Beyond)
    26. August 2016

    […] you're not familiar with lookup tables, I recommend checking out some use cases and learning about how flexible they can be. (When checking out those links, remember that "macros" […]

  5. Les
    15. April 2016

    Hello Eoghan: Thanks for your input and detailed response. I had missed Simo’s post in my research. I don’t think either solution will work for me as the URL structure I am working with is quite complicated. We are working with URL strings that are the result of a facetted search appliance. So you can imagine how messy things get!


    In this case, I’d like to grab ‘8336’ and output the actual product type. I have a matrix that matches up the numbers we get in facetted search with the actual product type. The hope was to do this in GTM so that the actual product type would come out the other end in GA.

    My other option is to take the raw data from GA and do some Excel magic. Right now that seems like the best approach.

    As an aside, the example I provided is basic as compared to what one gets once you start drilling down one’s search.

    I really appreciate your time and the effort you put into your response. 🙂

    • Eoghan Henn
      19. April 2016

      Hi Les! Sure sounds messy. Good luck with finding a solution! And if you do come up with a way of doing it in GTM, let us know 😉


  6. Les
    14. April 2016

    Good post Eoghan.

    So what about a situation where you you want to output a certain value when a url contains certain characters? e.g> and I want to output “Good Deal” based on the fact the the url contains ‘5346’

    • Eoghan Henn
      15. April 2016

      Hi Les!

      Unfortunately, GTM lookup tables only support one match type: “exact”. You need “contains” or “RegEx” so in order to achieve what you are looking for, you will have to implement a bit more than a lookup table. There are two solutions I can think of:

      First, I would like to refer you to Simo Ahava’s Simple RegEx Table for Google Tag Manager:

      If you manage to implement this, it should do the job.

      Second, there is another solution I have used in a similar case that does involve the GTM lookup table macro and a tiny little bit of JavaScript. Here we go:

      If your URLs always start with a four digit number like the one in your example, you can use a very simple script to extract this string and then use it as input value for a GTM lookup table.

      Here’s the script:

      function() {
      var str = {{Page Path}};
      return str.substring(1, 5);

      This will return characters 2 to 5 of your “Page Path” macro (so the four digit number in your example above). You just have to paste this script into a custom JavaScript variable in GTM and then use this new macro as input for your lookup table macro. In the lookup table, you can then match your four digit numbers with the output values you need.

      Please let me know if one of these solutions works for you or if you have further questions (sorry about my very brief description of the second solution).

      Thanks for your comment!


  7. Joao
    28. December 2015

    Hi Eoghan,

    I’ve been wondering, does lookup table suports regex?

    Like a radiobutton giving me numbers instead of names. and sometimes different numbers means the same thing.

    Something like this
    1|4|7 = Mastercard
    2|5 = Visa
    and so on (Is not working this way)

    Or i just have to do it like this

    1 = Mastercard
    2 = Visa
    4 = Mastercard
    5 = Visa
    7 = Mastercard

    Thanks in advance.

    • Eoghan Henn
      7. January 2016

      Hello Joao,

      Unfortunately, lookup tables do not support regex. The only available matching option is “equals”. But who knows, Google might introduce this future some time in future. I think it would be pretty useful.

      Anyhow, to answer your question: You will have to go with your secound idea (one line per input value).

      Talk soon,


  8. Heather
    18. December 2015


    Thanks for the awesome post! I was able to get this implemented and it is exactly what I am looking for.

    Question for you – I have lookup tables set for Source and Medium for social sites (fb, tw, li, gp) however I want to be able to customize the Campaign and Content on a per-URL basis.
    When i type in, I can see the source and medium in the real time report, however when I try, the traffic comes through as direct.

    Alternatively, would it be possible to have 2 url fragments in one URL? something like

    Thanks in advance for your help

    • Eoghan Henn
      22. December 2015

      Hello Heather,

      Thanks a lot for your interesting questions.

      Unfortunately, URLs like will not work with lookup tables, because GTM interprets everything that comes after the hash (#) as the URL fragment. So the URL fragment in this case would be “tw?utm_campaign=campaignTest”. As the matching option of lookup tables in GTM is always “equals” (and not “contains”), the lookup table variable will have no output in this case. That’s why your traffic shows as direct.

      There is a workaround for this. Instead of a lookup table you can set up a trigger for each URL fragment and use it for a separate Universal Analytics tag that sends the first page view of the session with the corresponding values for source and medium. Just use the same trigger as excluding trigger for your normal page view tag that sends all other page views to GA. I have implemented this method for a client that uses URL fragments for affiliate pages that append their own tracking parameters to the URLs that already hav URL fragments and it works amazingly well.

      However, I would not recommend using utm_campaign parameters without their triplet siblings utm_source and utm_medium. These three should alwys be used together and not separately.

      Your second idea of using two URL fragments like will not work either, because every URL can only have one URL fragment. It is important to keep this in mind when using the URL fragment solution for tracking traffic sources, as sometimes your destination URLs will already have URL fragments for other purposes. For example, your page might use URL fragments in anchor link URLs, such as In this case you can’t use a URL fragment to track traffic to

      To solve your problem, I would suggest you create URL fragment combinations of source, medium, campaign and content, just like I explained to Vert in a previous comment. You could use fragments like this:


      and so on…

      It’s not too much hassle to go to GTM before publishing a new link and adding some values to your lookup tables.

      I hope this helps! Please let me know if you have any additional questions.


  9. George
    17. December 2015

    Hi Eoghan,
    Would this method work on a site which uses iframes – where the GTM is placed on the iframe itself.

    Many thanks,

    • Eoghan Henn
      17. December 2015

      Hello George,

      Yes, alll of this will also work on a website that uses iframes. When you track things that happen in iframes, it is important that you include the GTM code in the documents that are loaded in the iframes and if these documents are hosted on different domains, you need cross domain tracking. Otherwise, Google Analytics would start a new session every time something happens on a different domain.

      If you have any additional questions on this, please just let me know!


  10. Vert
    21. October 2015

    Dear Eoghan,

    thank you for the great article! I stumbled upon the same Lunametric article and was interested in using the method for a cleaner UTM URL. I’d like to have my link as something like “” while it would be sent to GA as “” instead. I’m having difficulties implementing this, though. How should I set up my lookup table in GTM? I appreciate any pointers I can get. Thank you and keep up the good work!

    • Eoghan Henn
      21. October 2015

      Hello Vert,

      Thanks for your kind words.

      You will need three lookup tables to set this up, one for the dimension “source”, one for “medium”, and one for “campaign”. You then choose the URL fragment as input variable for each of the lookup tables and match it with the values for source, medium and campaign you want to send to GA.

      So your value pairs in the source lookup table would look like this:

      1 – testsource1
      2 – testsource2
      3 – testsource3
      4 – testsource4
      and so on…

      For the medium lookup table it would be this:

      1 – testmedium1
      2 – testmedium2
      3 – testmedium3
      4 – testmedium4
      and so on…

      And for campaign it would look like this:

      1 – testcampaign1
      2 – testcampaign2
      3 – testcampaign3
      4 – testcampiagn4
      and so on…

      Now how do you get the output of your lookup tables into GA?

      In your normal page view tag in GTM, you go to More settings > Fields to set and you define the following three fields:

      – campaignSource
      – campaignMedium
      – campaignName

      Then you populate the three fields with the output values of the three corresponding lookup tables. The values will now be sent to GA just as if you were using the UTM tracking parameters utm_source, utm_medium and utm_campaign.

      I hope this helps! Let me know if anything remains unclear.

      Best regards,


      • Vert
        22. October 2015

        Thank you, Eoghan! I was trying to fit all 3 parameters into 1 lookup table so that might be where I screwed up… I will give your method a shot and report back! It’s so very kind of you to take the time to answer a newbie question like mine! 🙂

        • Eoghan Henn
          23. October 2015

          Hi Vert! OK, let me know if it worked out for you.

      • Manu Kivila
        28. May 2016


        I just tried to implement something similar but couldn’t see anything (source didn’t change and it was still “direct / none) in real-time reports.

        Trying to implement tracking for instagram:

        Here’s my implementation (normal pageview tag):
        Real-time report:
        Lookup table:

        URL fragment is set as you showed.

        What would be wrong with the implementation? Why it doesn’t show up in real-time reports?

        • Eoghan Henn
          28. May 2016

          Hi Manu,

          Thanks for your comment. From what I can see, your implementation looks fine. Here’s what I would recommend:

          • If the real-time report doesn’t show the results you expect, but you can’t find any mistakes in your implementation, always check your normal reports after a few hours. The real-time report doesn’t always work properly and often shows different data from the final reports.
          • In GTM debugging mode, go to your page view tag and check in the properties under “Fields to set” if campaignSource is listed and has the desired output.
          • If you still find that it’s not working and you implemented everything correctly, you might want to try to send a value for campaignMedium too. I’ve never tested this, but I imagine that GA might have problems if you only submit a custom value for campaignSource, but not for campaignMedium. After all, these two dimensions are tied together very tightly.
          • I hope this helps. Let me know how it goes!


          • Eoghan Henn
            28. May 2016

            P.s.: I did just test that third thing I mentioned while I was writing the comment and when you only pass campaignSource, the dimension “Medium” shows as “(not set)” in the final reports. In the real-time report, however, my visits showed as “(direct) / (none)”. So I guess that’s what you were looking for! Does your first test show as “instagram / (not set)” in “Source/Medium”?


Leave a Reply