如何创建仅在网站首页上触发的规则? [英] How do I create a rule that will fire only on my site's home page?
问题描述
我正在使用Google跟踪代码管理器,并且正在尝试设置仅在我的网站首页上触发的规则.
I using Google Tag Manager and I am trying to setup a rule that will fire ONLY on my sites homepage.
问题是我不确定如何处理主页的所有URL排列.如何创建将处理的规则:
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."
此外,我们使用Sitecore并支持多种语言,因此首页网址也可以显示为:
Also, we use Sitecore and support multiple languages, so the homepage url can also display as:
"http://www.mysite.com/en"
我不确定访问者在网站上使用导航后如何处理插入到URL路径中的区域性标识符.
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.
是否可以使用OOTB Google跟踪代码管理器规则来处理这种情况,还是我必须实施跟踪代码管理器数据层?
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}}
给出了整个地址,而{{url domain}}
给出了域,而{{url path}}
给出了路径(包括初始正斜杠).
{{url}}
gives the whole address whereas {{url domain}}
just gives the domain and {{url path}}
just the path (including the initial forward slash).
这与http
和https
匹配,无论是否带有www
以及最后带有或不带有index.html
.它还与mysite.com/
和mysite.com
匹配(末尾没有正斜杠).如果要在首页末尾检查URL排列,可以执行以下操作:
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)?$
等.
此外,也不必转义正斜杠.实际上,转义正斜杠对我来说违反了GTM中的触发规则...
Also, forward slashes do NOT have to be escaped. In fact, escaping forward slashes broke the firing rule in GTM for me...
请参见 http://en.wikipedia.org/wiki/Regular_expression
并且如果您想忽略查询字符串(这是一件好事,因为大多数广告在URL中添加了utm_source
等查询关键字),您可以使用以下内容:
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)?/?(\?.*)?$
(请注意最后的(\?.*)?
)
这篇关于如何创建仅在网站首页上触发的规则?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!