跟踪客户在Magento中将产品添加到购物车
问题描述:
我遇到了Magento问题,我有几个将产品添加到购物车的CMS块,其中一些是促销页,其他类似产品生成器页面,添加了几个产品(它是制造其他东西的组件之王)的产品,我想知道客户是否在使用这些页面,是否可以像添加一个类似“utm”的字样,在后端显示“这个用户使用这个页面/ utm广告系列/不管“?跟踪客户在Magento中将产品添加到购物车
它必须要做一些会话,对吧?但除此之外,我无能为力。
答
您可能想要查看Google的Tagmanager for Analytics和DataLayers。有各种各样的扩展可用于此,但您可以自己实现它。即look at this
使用数据图层,您可以在每个页面上跟踪每个用户,将您想要的数据输出到需要的位置。 将头部包裹起来有点复杂,但它绝对是追踪和记录客户行为的最佳方式。
我实施本作目前由于同样的原因,通过调用一个自定义的头一个.phtml文件,并使用定义每页的标签PHP象下面这样:
<!-- Start GTM phtml -->
<?php if(Mage::getURL('checkout/onepage/success') == Mage::helper('core/url')->getCurrentUrl()) { ?>
<!-- GTM: Succes -->
<script>
dataLayer.push({
'ecommerce': {
'purchase': {
'actionField': {
'id': 'T12345',
'affiliation': 'xxx',
'revenue': 'xxx',
'tax': 'xxx',
'shipping': 'xxx'
},
'products': [{
'name':'productname',
'id':'123',
'price':'25.95',
'brand':'brandname',
'category':'clothing',
'quantity':'1'
},
{
'name':'productname',
'id':'345',
'price':'10.95',
'brand':'brandname',
'category':'apparel',
'quantity':'2'
}]
}
}
});
</script>
<?php } ?>
<?php if(Mage::getURL('checkout/cart') == Mage::helper('core/url')->getCurrentUrl()) { ?>
<!-- GTM: Cart -->
<?php } ?>
<?php if (strpos(Mage::helper('core/url')->getCurrentUrl(),'men') != false) : ?>
<!-- GTM: Men -->
<?php endif; ?>
<?php if($this->getRequest()->getControllerName()=='product') ://do something ?>
<!-- GTM: All Products -->
<script>
dataLayer.push({
'event':'addToCart',
'ecommerce': {
'currencyCode':'EUR',
'add':{
'products':[{
'name': 'Productname',
'id': '1234',
'price':'15.00'
'brand':'brandname'
'quantity':1
}]
}
}
});
</script>
<?php endif; ?>
<?php if (strpos(Mage::helper('core/url')->getCurrentUrl(),'woman/running') != false) : ?>
<!-- GTM: Woman Running -->
<script>
dataLayer.push({
'ecommerce': {
'purchase': {
'actionField': {
'id': 'T12345',
'affiliation': 'BK',
'revenue': 'BK',
'tax': 'BK',
'shipping': 'BK'
},
'products': [{
'name': 'Productname',
'id': '1234',
'price':'15.00'
'brand':'brandname'
'quantity':1
},
{
'name': 'Productname',
'id': '1234',
'price':'15.00'
'brand':'brandname'
'quantity':1
}]
}
}
});
</script>
<?php endif; ?>
<!-- Google Tag Manager -->
<noscript><iframe src="//www.googletagmanager.com/ns.html?id=XXX-XXXXXX"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','XXX-XXXXXX');</script>
<!-- End Google Tag Manager -->
正如你可以看到我使用不同的检查来触发特定页面上的图层。这些可以是精确的网址,也可以是包含关键字的网址(如“man”)。 的想法是,你与Magento的动态信息(echo $_product->getName();
和such)
而一个良好的开端更换所有的变量是,当然,Google Docs itself
感谢亚历克斯。我会有一个疯狂的。 – Pablo