How To Extract Hostname of External Domain in Google Tag Manager

How To Extract Hostname of External Domain in Google Tag Manager

This blog post is based on the thread in GTM forum:

https://productforums.google.com/forum/?utm_medium=email&utm_source=footer#!msg/tag-manager/lupx4brLNao/tBFfN0PlBAAJ

Let's say you link an image  on your blog post to Justin Cutroni's website. Here's the image and the link that it goes to: http://cutroni.com/blog/wp-content/uploads/Screen-Shot-2013-09-30-at-10.45.44-AM.png:

In you go to GTM > Preview mode, you can now see this variable populated with cutroni.com

Link Click Trigger with external domain clicked on.JPG

You can now create a trigger where:

Hostname does not equal your own website

Click URL matches RegEx jpg|png|svg|gif [in case you only want to capture image clicks to external domains - and know which domains did the traffic go to] AND click URL does not contain your own domain.

Once you have this, you can now setup an event where:

Category = Outbound image clicks

Action = {{page url}}

Label = {{External domain clicked on}}

and that's it.

Sample SQL Queries For Google Analytics BigQuery Public Dataset

Sample SQL Queries For Google Analytics BigQuery Public Dataset

How To Connect Multiple Google Analytics Accounts To R Studio [googleanalyticsR package]

How To Connect Multiple Google Analytics Accounts To R Studio [googleanalyticsR package]