Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fire GTM tag only if on homepage of the site

The homepage can also have extra GET params (e.g. utm tags and similar marketing variables). How can I make it work? Simple "end with http://example.com or http://example.com/" doesn't work cause the url might be http://example.com/?utm_campaign=text&...

Thanks!

like image 756
Grin Avatar asked Jul 18 '16 07:07

Grin


People also ask

Does Google Tag Manager need to be on every page?

To start collecting data, you need to put the Google tag in the code of your website. The Google tag must be on every page that has data you want to collect.

Where should GTM code be placed?

The first code block is best placed immediately after the web page's opening <head> tag, or as high in the <head> as possible. This helps to ensure that your Tag Manager configuration is available and ready when the rest of the page loads.

Why are my GTM tags not firing?

Incorrect trigger. The first thing to check why your tag did not fire in GTM is firing triggers. Here's a simple process to follow when this happens: Choose an event in the Preview and Debug console's event stream (left side) and click the tag that behaved unexpectedly.


3 Answers

The best practice is always install the GTM along you domain and execute it whenever you need. To launch a tag only in the home you need to use the following trigger. Add this on you custom HTML tag, take care of the equals.

enter image description here

like image 174
Kemen Paulos Plaza Avatar answered Nov 07 '22 09:11

Kemen Paulos Plaza


I know this is an old thread; but I found it after I solved this myself. I created a trigger for Page Path matches RegEx and used:

^\/(\?(.*))?$

What that does is matches for ONLY the hostname with no path (www.domain.com/) OR matches if a ? follows the /.

Might be another way to do this. Completed trigger:

Completed Trigger for matching homepage

like image 44
nocabt Avatar answered Nov 07 '22 11:11

nocabt


I've achieved the same using Page Path matches RegEx

^\/$|^\/\?

This means: match a string that begins (^) and ends ($) with / OR (|) that begins with /?

\ precedes special characters to denote that they should be treated as text and are not part of the expression.

like image 38
Jamie Avatar answered Nov 07 '22 11:11

Jamie