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){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(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
Best Answer
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.
app\etc\modules\Namespace_Googleoptimize.xml
app\code\local\Namespace\Googleoptimize\etc\config.xml
app\code\local\Namespace\Googleoptimize\etc\system.xml
app\code\local\Namespace\Googleoptimize\Helper\Data.php
app\code\local\Namespace\Googleoptimize\Block\Ga.php
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;
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;