0

我在使用 Magento 时遇到问题,我有几个 CMS 块可以将产品添加到购物车,其中一些是促销页面,另一些就像一个产品构建器页面,它添加了几个产品(这是制造其他东西的组件之王)到购物车,我想知道客户是否正在使用此页面,是否可以添加类似的“utm”,在我的后端显示“此用户使用此页面/utm 活动/其他”?

它必须与会话有关,对吧?但除此之外,我一无所知。

4

1 回答 1

1

您可能想查看 Google 的 Tagmanager for Analytics 和 DataLayers。有各种可用的扩展,尽管您可以自己实现它。即看看这个

使用数据层,您可以在所有页面上跟踪每个用户,在您想要的位置输出您想要的数据。绕着你的脑袋有点复杂,但这绝对是跟踪和记录客户行为的最佳方式。

我现在出于同样的原因实现这一点,方法是在头部调用自定义 .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 -->

如您所见,我使用不同的检查来触发特定页面上的图层。这些可以是精确的 url,也可以是包含关键字(如“man”)的 url。这个想法是用 Magento 的动态信息替换所有变量echo $_product->getName();等等)

一个好的起点当然是Google Docs 本身

于 2015-11-05T11:28:22.690 回答