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
and https
, with or without www
and with or without index.html
at the end. It also matches mysite.com/
and mysite.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:
^https?://(www\.)?mysite\.com/?(index\.html)?/?(\?.*)?$
(note the (\?.*)?
at the end)