未设置Magento Google Analytics(分析)产品类别 [英] Magento Google Analytics Product Category not set
问题描述
我尝试跟踪产品类别从magento到GA(在转化>电子商务>总览下),但是使用magento默认核心GA.php文件,其中包括以下部分:
/ app / code / core / Mage /GoogleAnalytics/Block/Ga.php
I am trying to track product category from magento to GA, (under Conversions>Ecommerce>overview), but with magento default core GA.php file dosent including this part: /app/code/core/Mage/GoogleAnalytics/Block/Ga.php
foreach ($order->getAllVisibleItems() as $item) {
$result[] = sprintf("_gaq.push(['_addItem', '%s', '%s', '%s', '%s', '%s', '%s']);",
$order->getIncrementId(),
$this->jsQuoteEscape($item->getSku()), $this->jsQuoteEscape($item->getName()),
null, // there is no "category" defined for the order item
$item->getBasePrice(), $item->getQtyOrdered()
);
}
*请注意,他们推荐类别字段并在其中添加空值。
*see, they commend out category field and put null right there.
我正在寻找一种解决方案,该解决方案不修改/ core中的magento,但解决/ local中的问题。
I am looking for a solution that do not modify the magento in the /core, but solve the problem in /local.
顺便说一句,我使用的是magento 1.7
BTW, I am using magento 1.7
希望有人可以帮助我,很多帮助:D
hopefully someone could help me out, many thx :D
推荐答案
我对Magento不太了解,但我相信您要做的就是将整个文件从核心复制到/本地文件夹并将其更改为包括类别。 Magento将始终在/ core之前在/ local中查找文件,但是路径必须匹配。因此,文件应位于以下位置:
I don't know much about Magento but I believe all you have to do is copy that whole file from core over to your /local folder and change it to include the category. Magento will always look for a file in /local before going to core, but the path have to match. So the file should live in:
/app/code/local/Mage/GoogleAnalytics/Block/Ga.php
您将遇到的另一个问题是Magento产品可以具有多个类别。因此,您可能只想抓取第一个文件并传递给GA。
Another problem you'll have is that Magento products can have several categories. so you probably want to grab just the first one and pass to GA.
因此文件的外观如下:
$_category = null;
$categoryIds = $_product->getCategoryIds();
if(count($categoryIds)) {
$firstCategoryId = $categoryIds[0];
$_category = Mage::getModel('catalog/category')->load($firstCategoryId);
}
foreach ($order->getAllVisibleItems() as $item) {
$result[] = sprintf("_gaq.push(['_addItem', '%s', '%s', '%s', '%s', '%s', '%s']);",
$order->getIncrementId(),
$this->jsQuoteEscape($item->getSku()), $this->jsQuoteEscape($item->getName()),
$_category,
$item->getBasePrice(), $item->getQtyOrdered()
);
}
基于
- how to get category name of current product (on product detail page) in magento
这篇关于未设置Magento Google Analytics(分析)产品类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!