I using Google Tag Manager and I am trying to setup a rule that will fire ONLY on my sites homepage.
The issue is that I am not certain how to handle all of the URL permutations of the homepage. How can I create a rule that will handle:
"http://" "https://" "http://www." "https://www."
Also, we use Sitecore and support multiple languages, so the homepage url can also display as:
"http://www.mysite.com/en"
I am not sure how to handle the culture identifier that is inserted into the URL path after a visitor has used the navigation on the site.
Is it possible to use the OOTB Google Tag Manager rules to handle this scenario, or will I have to implement a Tag Manager Data Layer?
The following rule would check if it's the homepage:
{{url}}
matches RegEx^https?://(www\.)?mysite\.com/?(index\.html)?$
{{url}}
gives the whole address whereas{{url domain}}
just gives the domain and{{url path}}
just the path (including the initial forward slash).This matches
http
andhttps
, with or withoutwww
and with or withoutindex.html
at the end. It also matchesmysite.com/
andmysite.com
(without the forward slash at the end). If you want to check for URL permutations at the end of the homepage, you could do something like:^https?://(www\.)?mysite\.com/?(en|es|fr)?$
etc.Also, forward slashes do NOT have to be escaped. In fact, escaping forward slashes broke the firing rule in GTM for me...
See http://en.wikipedia.org/wiki/Regular_expression
edit: and if you want to ignore the querystring (which is a good thing to do because most ads add query keys such as
utm_source
etc. to the url), you can have something like this:(note the
(\?.*)?
at the end)This is a super robust way to know it's your home page with either protocol and allow for a backslash all with one line of Regex...
Not sure sure why the initial double backslashes don't have to be escaped, but it works. Would have expected
^https?:\/\/www.mydomain\.com\/?$
Maybe someone else knows that :)Ok... so after researching the Google Tag Manager Forum, this can be accomplished by making separate url "ends with" rules for your site url and then your site url with a trailing forward slash such as:
I think it was the trailing slash that was confusing the matter as I was setting up the rules.