跟踪客户在 Magento 中将产品添加到购物车的位置
Tracking from where customer add product to cart in Magento
我在使用 Magento 时遇到问题,我有几个将产品添加到购物车的 CMS 块,其中一些是促销页面,其他类似于添加多个产品的产品构建器页面(它们是组件之王做其他事情)到购物车,我想知道客户是否正在使用此页面,是否可以添加一个 "utm" 类似的东西,它会显示在我的后端说 "this user used this page/utm campaign/whatever" ?
肯定跟session有关系吧?但除此之外,我一无所知。
您可能想查看 Google 的分析和数据层标签管理器。有各种各样的扩展可用于此,但您可以自己实现它。 IE。 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
我在使用 Magento 时遇到问题,我有几个将产品添加到购物车的 CMS 块,其中一些是促销页面,其他类似于添加多个产品的产品构建器页面(它们是组件之王做其他事情)到购物车,我想知道客户是否正在使用此页面,是否可以添加一个 "utm" 类似的东西,它会显示在我的后端说 "this user used this page/utm campaign/whatever" ?
肯定跟session有关系吧?但除此之外,我一无所知。
您可能想查看 Google 的分析和数据层标签管理器。有各种各样的扩展可用于此,但您可以自己实现它。 IE。 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