UPDATE: 希望这是问题的一个更好的解释:自定义变量
我想对产品SKU通过我的产品的详细信息页面,谷歌Analytics(分析)使用_setCustomVar
上。 我在Magento的1.4.0.1运行和我的分析异步代码是由<head>
部分默认GA模块插入,它看起来像这样:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxxxx-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
我想添加自定义变量有这个语法:
_gaq.push(['_setCustomVar',1,'View Product','<?php echo $_helper->productAttribute($_product, $_product->getSku(), 'sku') ?>',3]);
根据该分析文档,为了要记录的自定义变量,则_setCustomVar
之前,必须调用的_trackPageView
, 但有默认的Google分析模块在此不支持。此问题有两个问题:
- 如何在默认跟踪代码之前添加我的
_setCustomVar
函数? - 我如何可以加我
_setCustomVar
函数只在商品页面上?
原帖:
我试图存储产品的SKU通过在Analytics(分析)自定义变量访问者正在查看。这个语法是_gaq.push(['_setCustomVar',3,'View Product','SKU12345',2]);
。
显然这个代码段应只加在产品详细信息页面,而不是列表,购物车,或者结帐页面。所以,我已经试过编辑view.phtml
文件中app/design/frontend/default/my_package/template/catalog/product
中加入下面的代码:
<script>
_gaq.push(['_setCustomVar',
1,
'View Product',
'<?php echo $_helper->productAttribute($_product, $_product->getSku(), 'sku') ?>',
3]);
</script>
的问题是,我加入这个自定义变量基本跟踪代码,这是在默认情况下后加入<head>
部分,因此它不会记录在Google Analytics中。
我试图避免改变app/code/core/Mage/GoogleAnalytics/Block/Ga.php
与分析模块的核心文件,但我认为解决方案可能躺在那里。 如何添加一段代码,设置自定义变量,以便它出现的基本跟踪代码之前_gaq.push(['_trackPageview']);
内?
这是通过分析我提供异步代码:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxxxx-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
理念从here
注:如果您使用我使用的Magento 1.4.0.1和分析异步语法
您手动添加谷歌Analytics(分析)代码,您的页眉/页脚,或者你使用谷歌的Magento阿比... http://www.siteground.com/tutorials/magento/magento_google_analytics.htm ? –
我使用了Magento的核心分析模块就像你贴 – Bogdan