updating Analytics code for Google OptimizeGoogle Optimize snippet on MagentoHow to supplement Google Analytics push data during checkoutGoogle Analytics - put their code in manually or is it already included?Magento & Google Analytics - Tracking Code or Google API?wrong tracking code for Google Analytics?Google Analytics stopped working after Magento updateCanceled orders not updating in Google analyticsMagento 2 Google Universal Analytics codeConfiguring Google AnalyticsGoogle Optimize snippet on MagentoTrack backend sales on Google Analytics
Grade-school elementary algebra presented in an abstract-algebra style?
Is this homebrew "Cactus Grenade" cantrip balanced?
A burglar's sunglasses, a lady's odyssey
Does French have the English "short i" vowel?
Finding all files with a given extension whose base name is the name of the parent directory
Why would a rational buyer offer to buy with no conditions precedent?
Is superuser the same as root?
The Maltese Falcon
What are nvme namespaces? How do they work?
Navigating a quick return to previous employer
Expected maximum number of unpaired socks
Why does the Starter Set wizard have six spells in their spellbook?
Final exams: What is the most common protocol for scheduling?
What tokens are in the end of line?
Is there an idiom that means that you are in a very strong negotiation position in a negotiation?
Can a ring of spell storing and access to Find spells produce an endless menagerie?
Why did Jon Snow do this immoral act if he is so honorable?
Of strange atmospheres - the survivable but unbreathable
Shorten or merge multiple lines of `&> /dev/null &`
...And they were stumped for a long time
Co-author wants to put their current funding source in the acknowledgements section because they edited the paper
Are runways booked by airlines to land their planes?
What does it mean when a vocal teacher tell you that your lowest notes are heavy?
Count all vowels in string
updating Analytics code for Google Optimize
Google Optimize snippet on MagentoHow to supplement Google Analytics push data during checkoutGoogle Analytics - put their code in manually or is it already included?Magento & Google Analytics - Tracking Code or Google API?wrong tracking code for Google Analytics?Google Analytics stopped working after Magento updateCanceled orders not updating in Google analyticsMagento 2 Google Universal Analytics codeConfiguring Google AnalyticsGoogle Optimize snippet on MagentoTrack backend sales on Google Analytics
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
Google has released a new product - Google Optimize. Is it possible to modify the standard Universal Analytics code in Magento (enabled under Google API in 1.9.3) to implement the change?
The actual change needed is:
Paste into your existing Analytics snippet as shown below:
<script>
(function(i,s,o,g,r,a,m))(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-xxxxxx', 'auto');
ga('require', 'GTM-xxxxxx');
ga('send', 'pageview');
</script>
so only 1 extra line is needed
google-analytics google-api
add a comment |
Google has released a new product - Google Optimize. Is it possible to modify the standard Universal Analytics code in Magento (enabled under Google API in 1.9.3) to implement the change?
The actual change needed is:
Paste into your existing Analytics snippet as shown below:
<script>
(function(i,s,o,g,r,a,m))(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-xxxxxx', 'auto');
ga('require', 'GTM-xxxxxx');
ga('send', 'pageview');
</script>
so only 1 extra line is needed
google-analytics google-api
I tried updating the code and Google Snippet was not recognize by Google. My case here. Waiting on the community for help. magento.stackexchange.com/questions/167184/…
– Elvis
Apr 6 '17 at 15:21
add a comment |
Google has released a new product - Google Optimize. Is it possible to modify the standard Universal Analytics code in Magento (enabled under Google API in 1.9.3) to implement the change?
The actual change needed is:
Paste into your existing Analytics snippet as shown below:
<script>
(function(i,s,o,g,r,a,m))(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-xxxxxx', 'auto');
ga('require', 'GTM-xxxxxx');
ga('send', 'pageview');
</script>
so only 1 extra line is needed
google-analytics google-api
Google has released a new product - Google Optimize. Is it possible to modify the standard Universal Analytics code in Magento (enabled under Google API in 1.9.3) to implement the change?
The actual change needed is:
Paste into your existing Analytics snippet as shown below:
<script>
(function(i,s,o,g,r,a,m))(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-xxxxxx', 'auto');
ga('require', 'GTM-xxxxxx');
ga('send', 'pageview');
</script>
so only 1 extra line is needed
google-analytics google-api
google-analytics google-api
edited Apr 3 '17 at 13:56
Venu Joginpally
159221
159221
asked Apr 3 '17 at 12:13
RafalRafal
161
161
I tried updating the code and Google Snippet was not recognize by Google. My case here. Waiting on the community for help. magento.stackexchange.com/questions/167184/…
– Elvis
Apr 6 '17 at 15:21
add a comment |
I tried updating the code and Google Snippet was not recognize by Google. My case here. Waiting on the community for help. magento.stackexchange.com/questions/167184/…
– Elvis
Apr 6 '17 at 15:21
I tried updating the code and Google Snippet was not recognize by Google. My case here. Waiting on the community for help. magento.stackexchange.com/questions/167184/…
– Elvis
Apr 6 '17 at 15:21
I tried updating the code and Google Snippet was not recognize by Google. My case here. Waiting on the community for help. magento.stackexchange.com/questions/167184/…
– Elvis
Apr 6 '17 at 15:21
add a comment |
1 Answer
1
active
oldest
votes
I've thrown together a small module to add this in via a backend config for CE 1.9.3.x, hopefully it'll be useful to some.
appetcmodulesNamespace_Googleoptimize.xml
<?xml version="1.0"?>
<!--
/**
* Class Namespace_Googleoptimize
*
* @category Namespace
* @package Namespace_Googleoptimize
*/
-->
<config>
<modules>
<Namespace_Googleoptimize>
<active>true</active>
<codePool>local</codePool>
</Namespace_Googleoptimize>
</modules>
</config>
appcodelocalNamespaceGoogleoptimizeetcconfig.xml
<?xml version="1.0"?>
<!--
/**
* Namespace
*
* @category Namespace
* @package Namespace_Googleoptimize
*/
-->
<config>
<modules>
<Namespace_Googleoptimize>
<version>0.1.0</version>
</Namespace_Googleoptimize>
</modules>
<global>
<helpers>
<namespace_googleoptimize>
<class>Namespace_Googleoptimize_Helper</class>
</namespace_googleoptimize>
</helpers>
<blocks>
<googleanalytics>
<rewrite>
<ga>Namespace_Googleoptimize_Block_Ga</ga>
</rewrite>
</googleanalytics>
</blocks>
</global>
</config>
appcodelocalNamespaceGoogleoptimizeetcsystem.xml
<?xml version="1.0"?>
<config>
<sections>
<google translate="label" module="googleanalytics">
<label>Google API</label>
<tab>sales</tab>
<frontend_type>text</frontend_type>
<sort_order>340</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<groups>
<googleoptimize translate="label">
<label>Google Optimize</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>
<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>
<container translate="label">
<label>Container 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>
<comment>Enter the full container ID, ie GTM-XXXXXXX</comment>
</container>
</fields>
</googleoptimize>
</groups>
</google>
</sections>
</config>
appcodelocalNamespaceGoogleoptimizeHelperData.php
<?php
/**
* Namespace
*
* @category Namespace
* @package Namespace_Googleoptimize
*/
class Namespace_Googleoptimize_Helper_Data extends Mage_Core_Helper_Abstract
const XML_PATH_ACTIVE = 'google/googleoptimize/active';
const XML_PATH_CONTAINER = 'google/googleoptimize/container';
/**
* Whether Google Optimize is enabled in backend
*
* @param mixed $store
* @return bool
*/
public function isGoogleOptimizeEnabled($store = null)
return Mage::getStoreConfigFlag(self::XML_PATH_ACTIVE, $store);
/**
* Get Google Optimize Container ID
*
* @param string $store
* @return string
*/
public function getContainerId($store = null)
return Mage::getStoreConfig(self::XML_PATH_CONTAINER, $store);
appcodelocalNamespaceGoogleoptimizeBlockGa.php
<?php
/**
* Namespace
*
* @category Namespace
* @package Namespace_Googleoptimize
*/
class Namespace_Googleoptimize_Block_Ga extends Mage_GoogleAnalytics_Block_Ga
/**
* Render regular page tracking javascript code
* The custom "page name" may be set from layout or somewhere else. It must start from slash.
*
* @param string $accountId
* @return string
*/
protected function _getPageTrackingCodeUniversal($accountId)
if ($this->helper('namespace_googleoptimize')->isGoogleOptimizeEnabled())
$containerId = $this->helper('namespace_googleoptimize')->getContainerId();
return "
ga('create', '$this->jsQuoteEscape($accountId)', 'auto');
" . $this->_getAnonymizationCode() . "
ga('require', '$containerId');
ga('send', 'pageview');
";
else
return "
ga('create', '$this->jsQuoteEscape($accountId)', 'auto');
" . $this->_getAnonymizationCode() . "
ga('send', 'pageview');
";
/**
* Is Googel Optimize Enabled
*
* @return bool
*/
protected function _isEnabled()
return Mage::helper('namespace_googleoptimize')->isGoogleOptimizeEnabled();
It's worth noting that this might be the route required for you even if you are using Tag Manager.
Despite the fact that Tag Manager has a default tag for Google Optimize built in, their own docs say;
While it’s possible to deploy the Optimize plugin via Google Tag Manager, it will often result in significantly increased latency
https://support.google.com/360suite/optimize/answer/7359264?hl=en
And they are not kidding. I was running an extremely basic test and this resulted in a very long lag before the site was rendered, as I used the JS that prevents the FOUC.
See backend here config;
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f167407%2fupdating-analytics-code-for-google-optimize%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I've thrown together a small module to add this in via a backend config for CE 1.9.3.x, hopefully it'll be useful to some.
appetcmodulesNamespace_Googleoptimize.xml
<?xml version="1.0"?>
<!--
/**
* Class Namespace_Googleoptimize
*
* @category Namespace
* @package Namespace_Googleoptimize
*/
-->
<config>
<modules>
<Namespace_Googleoptimize>
<active>true</active>
<codePool>local</codePool>
</Namespace_Googleoptimize>
</modules>
</config>
appcodelocalNamespaceGoogleoptimizeetcconfig.xml
<?xml version="1.0"?>
<!--
/**
* Namespace
*
* @category Namespace
* @package Namespace_Googleoptimize
*/
-->
<config>
<modules>
<Namespace_Googleoptimize>
<version>0.1.0</version>
</Namespace_Googleoptimize>
</modules>
<global>
<helpers>
<namespace_googleoptimize>
<class>Namespace_Googleoptimize_Helper</class>
</namespace_googleoptimize>
</helpers>
<blocks>
<googleanalytics>
<rewrite>
<ga>Namespace_Googleoptimize_Block_Ga</ga>
</rewrite>
</googleanalytics>
</blocks>
</global>
</config>
appcodelocalNamespaceGoogleoptimizeetcsystem.xml
<?xml version="1.0"?>
<config>
<sections>
<google translate="label" module="googleanalytics">
<label>Google API</label>
<tab>sales</tab>
<frontend_type>text</frontend_type>
<sort_order>340</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<groups>
<googleoptimize translate="label">
<label>Google Optimize</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>
<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>
<container translate="label">
<label>Container 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>
<comment>Enter the full container ID, ie GTM-XXXXXXX</comment>
</container>
</fields>
</googleoptimize>
</groups>
</google>
</sections>
</config>
appcodelocalNamespaceGoogleoptimizeHelperData.php
<?php
/**
* Namespace
*
* @category Namespace
* @package Namespace_Googleoptimize
*/
class Namespace_Googleoptimize_Helper_Data extends Mage_Core_Helper_Abstract
const XML_PATH_ACTIVE = 'google/googleoptimize/active';
const XML_PATH_CONTAINER = 'google/googleoptimize/container';
/**
* Whether Google Optimize is enabled in backend
*
* @param mixed $store
* @return bool
*/
public function isGoogleOptimizeEnabled($store = null)
return Mage::getStoreConfigFlag(self::XML_PATH_ACTIVE, $store);
/**
* Get Google Optimize Container ID
*
* @param string $store
* @return string
*/
public function getContainerId($store = null)
return Mage::getStoreConfig(self::XML_PATH_CONTAINER, $store);
appcodelocalNamespaceGoogleoptimizeBlockGa.php
<?php
/**
* Namespace
*
* @category Namespace
* @package Namespace_Googleoptimize
*/
class Namespace_Googleoptimize_Block_Ga extends Mage_GoogleAnalytics_Block_Ga
/**
* Render regular page tracking javascript code
* The custom "page name" may be set from layout or somewhere else. It must start from slash.
*
* @param string $accountId
* @return string
*/
protected function _getPageTrackingCodeUniversal($accountId)
if ($this->helper('namespace_googleoptimize')->isGoogleOptimizeEnabled())
$containerId = $this->helper('namespace_googleoptimize')->getContainerId();
return "
ga('create', '$this->jsQuoteEscape($accountId)', 'auto');
" . $this->_getAnonymizationCode() . "
ga('require', '$containerId');
ga('send', 'pageview');
";
else
return "
ga('create', '$this->jsQuoteEscape($accountId)', 'auto');
" . $this->_getAnonymizationCode() . "
ga('send', 'pageview');
";
/**
* Is Googel Optimize Enabled
*
* @return bool
*/
protected function _isEnabled()
return Mage::helper('namespace_googleoptimize')->isGoogleOptimizeEnabled();
It's worth noting that this might be the route required for you even if you are using Tag Manager.
Despite the fact that Tag Manager has a default tag for Google Optimize built in, their own docs say;
While it’s possible to deploy the Optimize plugin via Google Tag Manager, it will often result in significantly increased latency
https://support.google.com/360suite/optimize/answer/7359264?hl=en
And they are not kidding. I was running an extremely basic test and this resulted in a very long lag before the site was rendered, as I used the JS that prevents the FOUC.
See backend here config;
add a comment |
I've thrown together a small module to add this in via a backend config for CE 1.9.3.x, hopefully it'll be useful to some.
appetcmodulesNamespace_Googleoptimize.xml
<?xml version="1.0"?>
<!--
/**
* Class Namespace_Googleoptimize
*
* @category Namespace
* @package Namespace_Googleoptimize
*/
-->
<config>
<modules>
<Namespace_Googleoptimize>
<active>true</active>
<codePool>local</codePool>
</Namespace_Googleoptimize>
</modules>
</config>
appcodelocalNamespaceGoogleoptimizeetcconfig.xml
<?xml version="1.0"?>
<!--
/**
* Namespace
*
* @category Namespace
* @package Namespace_Googleoptimize
*/
-->
<config>
<modules>
<Namespace_Googleoptimize>
<version>0.1.0</version>
</Namespace_Googleoptimize>
</modules>
<global>
<helpers>
<namespace_googleoptimize>
<class>Namespace_Googleoptimize_Helper</class>
</namespace_googleoptimize>
</helpers>
<blocks>
<googleanalytics>
<rewrite>
<ga>Namespace_Googleoptimize_Block_Ga</ga>
</rewrite>
</googleanalytics>
</blocks>
</global>
</config>
appcodelocalNamespaceGoogleoptimizeetcsystem.xml
<?xml version="1.0"?>
<config>
<sections>
<google translate="label" module="googleanalytics">
<label>Google API</label>
<tab>sales</tab>
<frontend_type>text</frontend_type>
<sort_order>340</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<groups>
<googleoptimize translate="label">
<label>Google Optimize</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>
<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>
<container translate="label">
<label>Container 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>
<comment>Enter the full container ID, ie GTM-XXXXXXX</comment>
</container>
</fields>
</googleoptimize>
</groups>
</google>
</sections>
</config>
appcodelocalNamespaceGoogleoptimizeHelperData.php
<?php
/**
* Namespace
*
* @category Namespace
* @package Namespace_Googleoptimize
*/
class Namespace_Googleoptimize_Helper_Data extends Mage_Core_Helper_Abstract
const XML_PATH_ACTIVE = 'google/googleoptimize/active';
const XML_PATH_CONTAINER = 'google/googleoptimize/container';
/**
* Whether Google Optimize is enabled in backend
*
* @param mixed $store
* @return bool
*/
public function isGoogleOptimizeEnabled($store = null)
return Mage::getStoreConfigFlag(self::XML_PATH_ACTIVE, $store);
/**
* Get Google Optimize Container ID
*
* @param string $store
* @return string
*/
public function getContainerId($store = null)
return Mage::getStoreConfig(self::XML_PATH_CONTAINER, $store);
appcodelocalNamespaceGoogleoptimizeBlockGa.php
<?php
/**
* Namespace
*
* @category Namespace
* @package Namespace_Googleoptimize
*/
class Namespace_Googleoptimize_Block_Ga extends Mage_GoogleAnalytics_Block_Ga
/**
* Render regular page tracking javascript code
* The custom "page name" may be set from layout or somewhere else. It must start from slash.
*
* @param string $accountId
* @return string
*/
protected function _getPageTrackingCodeUniversal($accountId)
if ($this->helper('namespace_googleoptimize')->isGoogleOptimizeEnabled())
$containerId = $this->helper('namespace_googleoptimize')->getContainerId();
return "
ga('create', '$this->jsQuoteEscape($accountId)', 'auto');
" . $this->_getAnonymizationCode() . "
ga('require', '$containerId');
ga('send', 'pageview');
";
else
return "
ga('create', '$this->jsQuoteEscape($accountId)', 'auto');
" . $this->_getAnonymizationCode() . "
ga('send', 'pageview');
";
/**
* Is Googel Optimize Enabled
*
* @return bool
*/
protected function _isEnabled()
return Mage::helper('namespace_googleoptimize')->isGoogleOptimizeEnabled();
It's worth noting that this might be the route required for you even if you are using Tag Manager.
Despite the fact that Tag Manager has a default tag for Google Optimize built in, their own docs say;
While it’s possible to deploy the Optimize plugin via Google Tag Manager, it will often result in significantly increased latency
https://support.google.com/360suite/optimize/answer/7359264?hl=en
And they are not kidding. I was running an extremely basic test and this resulted in a very long lag before the site was rendered, as I used the JS that prevents the FOUC.
See backend here config;
add a comment |
I've thrown together a small module to add this in via a backend config for CE 1.9.3.x, hopefully it'll be useful to some.
appetcmodulesNamespace_Googleoptimize.xml
<?xml version="1.0"?>
<!--
/**
* Class Namespace_Googleoptimize
*
* @category Namespace
* @package Namespace_Googleoptimize
*/
-->
<config>
<modules>
<Namespace_Googleoptimize>
<active>true</active>
<codePool>local</codePool>
</Namespace_Googleoptimize>
</modules>
</config>
appcodelocalNamespaceGoogleoptimizeetcconfig.xml
<?xml version="1.0"?>
<!--
/**
* Namespace
*
* @category Namespace
* @package Namespace_Googleoptimize
*/
-->
<config>
<modules>
<Namespace_Googleoptimize>
<version>0.1.0</version>
</Namespace_Googleoptimize>
</modules>
<global>
<helpers>
<namespace_googleoptimize>
<class>Namespace_Googleoptimize_Helper</class>
</namespace_googleoptimize>
</helpers>
<blocks>
<googleanalytics>
<rewrite>
<ga>Namespace_Googleoptimize_Block_Ga</ga>
</rewrite>
</googleanalytics>
</blocks>
</global>
</config>
appcodelocalNamespaceGoogleoptimizeetcsystem.xml
<?xml version="1.0"?>
<config>
<sections>
<google translate="label" module="googleanalytics">
<label>Google API</label>
<tab>sales</tab>
<frontend_type>text</frontend_type>
<sort_order>340</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<groups>
<googleoptimize translate="label">
<label>Google Optimize</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>
<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>
<container translate="label">
<label>Container 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>
<comment>Enter the full container ID, ie GTM-XXXXXXX</comment>
</container>
</fields>
</googleoptimize>
</groups>
</google>
</sections>
</config>
appcodelocalNamespaceGoogleoptimizeHelperData.php
<?php
/**
* Namespace
*
* @category Namespace
* @package Namespace_Googleoptimize
*/
class Namespace_Googleoptimize_Helper_Data extends Mage_Core_Helper_Abstract
const XML_PATH_ACTIVE = 'google/googleoptimize/active';
const XML_PATH_CONTAINER = 'google/googleoptimize/container';
/**
* Whether Google Optimize is enabled in backend
*
* @param mixed $store
* @return bool
*/
public function isGoogleOptimizeEnabled($store = null)
return Mage::getStoreConfigFlag(self::XML_PATH_ACTIVE, $store);
/**
* Get Google Optimize Container ID
*
* @param string $store
* @return string
*/
public function getContainerId($store = null)
return Mage::getStoreConfig(self::XML_PATH_CONTAINER, $store);
appcodelocalNamespaceGoogleoptimizeBlockGa.php
<?php
/**
* Namespace
*
* @category Namespace
* @package Namespace_Googleoptimize
*/
class Namespace_Googleoptimize_Block_Ga extends Mage_GoogleAnalytics_Block_Ga
/**
* Render regular page tracking javascript code
* The custom "page name" may be set from layout or somewhere else. It must start from slash.
*
* @param string $accountId
* @return string
*/
protected function _getPageTrackingCodeUniversal($accountId)
if ($this->helper('namespace_googleoptimize')->isGoogleOptimizeEnabled())
$containerId = $this->helper('namespace_googleoptimize')->getContainerId();
return "
ga('create', '$this->jsQuoteEscape($accountId)', 'auto');
" . $this->_getAnonymizationCode() . "
ga('require', '$containerId');
ga('send', 'pageview');
";
else
return "
ga('create', '$this->jsQuoteEscape($accountId)', 'auto');
" . $this->_getAnonymizationCode() . "
ga('send', 'pageview');
";
/**
* Is Googel Optimize Enabled
*
* @return bool
*/
protected function _isEnabled()
return Mage::helper('namespace_googleoptimize')->isGoogleOptimizeEnabled();
It's worth noting that this might be the route required for you even if you are using Tag Manager.
Despite the fact that Tag Manager has a default tag for Google Optimize built in, their own docs say;
While it’s possible to deploy the Optimize plugin via Google Tag Manager, it will often result in significantly increased latency
https://support.google.com/360suite/optimize/answer/7359264?hl=en
And they are not kidding. I was running an extremely basic test and this resulted in a very long lag before the site was rendered, as I used the JS that prevents the FOUC.
See backend here config;
I've thrown together a small module to add this in via a backend config for CE 1.9.3.x, hopefully it'll be useful to some.
appetcmodulesNamespace_Googleoptimize.xml
<?xml version="1.0"?>
<!--
/**
* Class Namespace_Googleoptimize
*
* @category Namespace
* @package Namespace_Googleoptimize
*/
-->
<config>
<modules>
<Namespace_Googleoptimize>
<active>true</active>
<codePool>local</codePool>
</Namespace_Googleoptimize>
</modules>
</config>
appcodelocalNamespaceGoogleoptimizeetcconfig.xml
<?xml version="1.0"?>
<!--
/**
* Namespace
*
* @category Namespace
* @package Namespace_Googleoptimize
*/
-->
<config>
<modules>
<Namespace_Googleoptimize>
<version>0.1.0</version>
</Namespace_Googleoptimize>
</modules>
<global>
<helpers>
<namespace_googleoptimize>
<class>Namespace_Googleoptimize_Helper</class>
</namespace_googleoptimize>
</helpers>
<blocks>
<googleanalytics>
<rewrite>
<ga>Namespace_Googleoptimize_Block_Ga</ga>
</rewrite>
</googleanalytics>
</blocks>
</global>
</config>
appcodelocalNamespaceGoogleoptimizeetcsystem.xml
<?xml version="1.0"?>
<config>
<sections>
<google translate="label" module="googleanalytics">
<label>Google API</label>
<tab>sales</tab>
<frontend_type>text</frontend_type>
<sort_order>340</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<groups>
<googleoptimize translate="label">
<label>Google Optimize</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>
<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>
<container translate="label">
<label>Container 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>
<comment>Enter the full container ID, ie GTM-XXXXXXX</comment>
</container>
</fields>
</googleoptimize>
</groups>
</google>
</sections>
</config>
appcodelocalNamespaceGoogleoptimizeHelperData.php
<?php
/**
* Namespace
*
* @category Namespace
* @package Namespace_Googleoptimize
*/
class Namespace_Googleoptimize_Helper_Data extends Mage_Core_Helper_Abstract
const XML_PATH_ACTIVE = 'google/googleoptimize/active';
const XML_PATH_CONTAINER = 'google/googleoptimize/container';
/**
* Whether Google Optimize is enabled in backend
*
* @param mixed $store
* @return bool
*/
public function isGoogleOptimizeEnabled($store = null)
return Mage::getStoreConfigFlag(self::XML_PATH_ACTIVE, $store);
/**
* Get Google Optimize Container ID
*
* @param string $store
* @return string
*/
public function getContainerId($store = null)
return Mage::getStoreConfig(self::XML_PATH_CONTAINER, $store);
appcodelocalNamespaceGoogleoptimizeBlockGa.php
<?php
/**
* Namespace
*
* @category Namespace
* @package Namespace_Googleoptimize
*/
class Namespace_Googleoptimize_Block_Ga extends Mage_GoogleAnalytics_Block_Ga
/**
* Render regular page tracking javascript code
* The custom "page name" may be set from layout or somewhere else. It must start from slash.
*
* @param string $accountId
* @return string
*/
protected function _getPageTrackingCodeUniversal($accountId)
if ($this->helper('namespace_googleoptimize')->isGoogleOptimizeEnabled())
$containerId = $this->helper('namespace_googleoptimize')->getContainerId();
return "
ga('create', '$this->jsQuoteEscape($accountId)', 'auto');
" . $this->_getAnonymizationCode() . "
ga('require', '$containerId');
ga('send', 'pageview');
";
else
return "
ga('create', '$this->jsQuoteEscape($accountId)', 'auto');
" . $this->_getAnonymizationCode() . "
ga('send', 'pageview');
";
/**
* Is Googel Optimize Enabled
*
* @return bool
*/
protected function _isEnabled()
return Mage::helper('namespace_googleoptimize')->isGoogleOptimizeEnabled();
It's worth noting that this might be the route required for you even if you are using Tag Manager.
Despite the fact that Tag Manager has a default tag for Google Optimize built in, their own docs say;
While it’s possible to deploy the Optimize plugin via Google Tag Manager, it will often result in significantly increased latency
https://support.google.com/360suite/optimize/answer/7359264?hl=en
And they are not kidding. I was running an extremely basic test and this resulted in a very long lag before the site was rendered, as I used the JS that prevents the FOUC.
See backend here config;
answered Aug 8 '17 at 19:16
McNabMcNab
86511219
86511219
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f167407%2fupdating-analytics-code-for-google-optimize%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I tried updating the code and Google Snippet was not recognize by Google. My case here. Waiting on the community for help. magento.stackexchange.com/questions/167184/…
– Elvis
Apr 6 '17 at 15:21