How-To Public

Options for Enabling Triggers in Google Tag Manager

How to enable triggers on all pages

Page URL -> matches RegEx -> .*

How to limit enabling triggers to only a specific website

Option 1: Is the desired domain name in the current page’s hostname?

Page Hostname -> contains ->

Option 2: Using regular expressions to require that the hostname string must be at the beginning of the Page Hostname or may be optionally preceeded by a “www.”.

Page Hostname -> matches RegEx (ignore case) – ^(www\.)?

What if you want to use a variable to store the desired website hostname? This potentially means that you can set up your GTM container to only have one place where you need to edit the hostname.

Option 3: Using custom JavaScript variable to pull the hostname from a custom constant variable.

function() {
// What: IsLocalWebsite – Function to determine whether the GTM Page Hostname (built-in variable) for the current page represents the local website hostname (as defined by the GTM Local Website Hostname custom constant variable).
// Who: Jan Macario
// When: 20170622

// Build regex string
var strRegex = “^(www\.)?” + “{{Local Website Hostname}}”;

// Create regex variable
var regex = new RegExp(strRegex,”gi”);

//Test page hostname against regex
if (regex.test(“{{Page Hostname}}”)) { return “true”; }
//If no match, return false
return “false”;