Magento将字段添加到Google Analytics(分析)代码中 [英] Magento get field added to Google Analytics code

查看:85
本文介绍了Magento将字段添加到Google Analytics(分析)代码中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经向Google Analytics(分析)模块添加了一个字段.(所以这个问题是一个通用问题,在这种情况下是分析模块)

I've added a field to the Google Analytics module. (so this question is a general one, in this case with the Analytics module)

看起来像这样(system.xml)

Looks like this (system.xml)

<another_code translate="label">
    <label>Another code</label>
    <frontend_type>text</frontend_type>
    <sort_order>10</sort_order>
    <show_in_default>1</show_in_default>
    <show_in_website>1</show_in_website>
    <show_in_store>1</show_in_store>
    <fields>
        <active translate="label">
            <label>Enable</label>
            <frontend_type>select</frontend_type>
            <source_model>adminhtml/system_config_source_yesno</source_model>
            <sort_order>10</sort_order>
            <show_in_default>1</show_in_default>
            <show_in_website>1</show_in_website>
            <show_in_store>1</show_in_store>
        </active>
        <account translate="label">
            <label>Account Id</label>
            <frontend_type>text</frontend_type>
            <sort_order>20</sort_order>
            <show_in_default>1</show_in_default>
            <show_in_website>1</show_in_website>
            <show_in_store>1</show_in_store>
        </account>
    </fields>
</another_code>

这很好用,get 已添加到数据库中.但是...

This works fine, get's added to the DB. But...

如何在前端获得它?如果我想获取< label>帐户ID</label>

How do I get it in the frontend? What would be the next step if I want to get the <label>Account Id</label>

推荐答案

要从上述示例中获取帐户ID"值

To get 'Account Id' value from above example

Mage :: getStoreConfig('google/another_code/account')

Mage::getStoreConfig('google/another_code/account')

对核心进行更改永远不是一个好主意,因此您可以创建一个自定义模块来扩展Google Analytics(分析)

It is never a good idea to make changes to core so you could create a custom module to extend google Analytics

在app/code/local/MageIgniter/GoogleAnalytics/etc/system.xml中(从上面复制system.xml)

in app/code/local/MageIgniter/GoogleAnalytics/etc/system.xml (copy system.xml from above)

<config>
    <sections>
        <google translate="label" module="googleanalytics">
            <label>Google API</label>
            <tab>sales</tab>
            ....
           <another_code translate="label">

在app/code/local/MageIgniter/GoogleAnalytics/etc/config.xml中

in app/code/local/MageIgniter/GoogleAnalytics/etc/config.xml

  <config>
    <modules>
        <MageIgniter_GoogleAnalytics>
            <version>0.1.0</version>
        </MageIgniter_GoogleAnalytics>
    </modules>
    <global>
        <blocks>
            <googleanalytics>
                <rewrite>
                    <ga>MageIgniter_GoogleAnalytics_Block_Ga</ga>
                </rewrite>
            </googleanalytics>
        </blocks>
    </global>
  </config>

在/app/code/local/MageIgniter/GoogleAnalytics/Block/Ga.php中创建

Create in /app/code/local/MageIgniter/GoogleAnalytics/Block/Ga.php

class MageIgniter_GoogleAnalytics_Block_Ga extends Mage_GoogleAnalytics_Block_Ga
{

     function _getPageTrackingCode($accountId){
         // to get 'Account Id' value from above example
         Mage::getStoreConfig('google/another_code/account')
     } 

     ........
}

请参阅/app/code/core/Mage/GoogleAnalytics/Block/Ga.php或 Magento产品详细信息页面上的自定义变量获得更多帮助

See /app/code/core/Mage/GoogleAnalytics/Block/Ga.php or Custom variables on product details page in Magento for more help

这篇关于Magento将字段添加到Google Analytics(分析)代码中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆