简体   繁体   English

如何将Google Analytics(分析)与Sitecore 6结合使用?

[英]How do I use Google Analytics with Sitecore 6?

I know that I need to add the tracking code snippet at the bottom of all my pages, but is there a central location to do this? 我知道我需要在所有页面的底部添加跟踪代码段,但是这样做的中心位置吗?

Or do I need to add this tracking code to all of my templates? 还是我需要将此跟踪代码添加到所有模板中?

I guess that I could wrap the snippet in a user control, or external .js file, and reference it on each page, but is there a global footer somewhere? 我想我可以将代码段包装在用户控件或外部.js文件中,并在每个页面上引用它,但是某个地方是否有全局页脚? The site I'm working on has about 30-40 layouts, and adding it to each one would be a pain! 我正在工作的网站大约有30-40种布局,将其添加到每个布局中会很痛苦!

Thanks in advance! 提前致谢!

Actually, the role of a Sitecore layout is exactly this; 实际上,Sitecore布局的作用就是这样。 to act as a global file that all individual page templates "derive" from. 充当所有单个页面模板“派生自”的全局文件。

Normally you'd stick the analytics code into the master layout, and use Sitecore sublayout/placeholder techniques to construct the various page templates you need. 通常,您会将分析代码粘贴到主布局中,并使用Sitecore子布局/占位符技术来构建所需的各种页面模板。 You would not normally need more than perhaps one or two layouts for any device you are serving content to. 对于向其提供内容的任何设备,您通常不需要一个或两个以上的布局。 And I guess for most sites, the only device in use is regular web content delivery. 而且我想对于大多数网站而言,唯一使用的设备就是常规的Web内容交付。

That being said, what you could do, is have all the layouts inherit their codebase from a common base class (inheriting from Page), and inject the google code centrally from here. 话虽这么说,您可以做的是让所有布局都从一个通用的基类(继承自Page)继承其代码库,并从此处集中注入google代码。 Would still require you to go through all layout files however. 但是仍然需要您浏览所有布局文件。

I have not tried the module, I think that is codebehind version. 我没有尝试过该模块,我认为这是代码隐藏版本。 I have made this in XSLT, its pretty fast and easy to make. 我已经在XSLT中做到了这一点,它非常快速且易于制作。 I have footer.xslt where I put the code that simply checks if page you are standing on uses template that I want to index and does not belong to page names that I want to exclude. 我有footer.xslt,我在其中放置的代码只是检查您所站在的页面是否使用我要索引的模板,而该模板不属于我要排除的页面名称。 Then I have an item with a custom template for Google Analytics with following memo fields. 然后,我有一个带有自定义模板的Google Analytics(分析)项目,其中包含以下备注字段。 IncludeTemplates -field contains list of templates that I want to include for analytics : ExcludeItemsNames -field for excluding pages by item name IncludeTemplates -field包含要包含在分析中的模板的列表:ExcludeItemsNames -field,用于按项目名称排除页面

contains($includeTemplates, concat('|',./@template,'|')) and not(contains($excludeItemNames, concat('|',./@template,'|')))

Remember @key and @template is always in small letters 记住@key和@template总是用小写字母

If you run many domains don't forget to add pageTracker._setDomainName("www.example.com"); 如果您运行许多域,请不要忘记添加pageTracker._setDomainName(“ www.example.com”);。 in analytics script so you can separate sub-domains etc. if they use same footer.xslt 在分析脚本中,因此您可以分隔子域等(如果它们使用相同的footer.xslt)

Normally we consider the actual Google code as content. 通常,我们将实际的Google代码视为内容。 Within Sitecore we normally have a settings folder, something like /sitecore/content/settings. 在Sitecore中,我们通常有一个设置文件夹,如/ sitecore / content / settings。 This exists outside the root of the site. 它存在于站点的根目录之外。 Beneath this have a settings item with a plain multi-line text field, I think the field type is memo or something similar. 在此之下有一个带有纯多行文本字段的设置项,我认为该字段类型是备忘或类似内容。

Afterwards create an XSLT that renders out the content of this settings item. 之后,创建一个XSLT来渲染此设置项的内容。 Something like (assuming the field is called value in the setting item): 诸如此类(假设该字段在设置项中称为值):

<xsl:value-of select="sc:fld('Value','/sitecore/content/settings/footerJavaScript')" />

You may or may not need to set the disable-output-escaping attribute. 您可能需要也可能不需要设置disable-output-escaping属性。

Then on the aspx page that your pages use as the template add a control that looks at the xslt rendering: 然后在您的页面用作模板的aspx页面上,添加一个查看xslt呈现的控件:

<sc:XslFile runat="server" Path="/xsl/footerJavaScript" />

The reason that we normally keep the javascript as content is this allows the client to change the analytics code without having to contact us. 我们通常将javascript保留为内容的原因是,这使客户无需联系我们即可更改分析代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在可点击的Flash标语上使用Google Analytics _trackEvent? - How do I use Google Analytics _trackEvent on a clickable Flash banner? 如何在 ASP.NET 中使用 Google Analytics? - How do I use Google Analytics in ASP.NET? 我如何为社区成员使用 Google Analytics? - How do I use Google Analytics for community members? 如何将trackPageView与Google Analytics(分析)(最新版本)一起使用? - How do I use trackPageView with Google Analytics (newest version)? 如何在Google Analytics(分析)中正确使用CustomVars? - How do i properly use CustomVars in google analytics? 如何将 Google Analytics API 与 Zend OAuth 一起使用? - How do I use Google Analytics API with Zend OAuth? 如何更改 Google Analytics 集成? - How do I change the Google Analytics Integration? 使用以下工具时,如何跟踪(Google Analytics(分析))单个文件的下载 <asp:hyperlink> 标签? - How do I track (Google Analytics) individual file downloads when I use the <asp:hyperlink> tag? 如何读取Google Analytics(分析)广告系列字符串以个性化Sitecore中的组件 - How to Read Google Analytics Campaign String to Personalize Component in Sitecore 如何在rails控制器中使用Google Analytics自定义事件? - How do I use Google Analytics custom events inside my rails controller?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM