Page 2 of 2
Re: [SOLVED] Google Analytics - New Version Causing Problems
Posted: Mon Apr 14, 2014 9:22 am
by velden
One little note:
Maybe it's wise to use a trim function on the foo variable. In case an editor accidently pastes a (invisible) space inside the box. That would possibly break the GA function.
I did not test it but I think {trim($foo)} and/or {$foo|trim} should work.
Re: [SOLVED] Google Analytics - New Version Causing Problems
Posted: Mon Apr 14, 2014 10:10 am
by govicinity
@Velden, thanks, great suggestion, just tried this on one of the sites we run
Code: Select all
{$cgsimple->get_page_content('blah','Google_Analytics','foo')}
{if !empty($foo)}
{literal}<__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','//www.google-analytics.com/analytics.js','ga');
ga('create', '{/literal}{$foo|trim}', '{$smarty.server.HTTP_HOST}{literal}');
ga('send', 'pageview');
</__script>{/literal}
{/if}
Added an extra space at the end of the GA code to test it, and it stripped it out nicely.
Re: [SOLVED] Google Analytics - New Version Causing Problems
Posted: Mon Apr 14, 2014 12:52 pm
by govicinity
PS, anyone using this, please make sure you remove the underscores from the <__script__> </__script> tags in the code I have provided, the forum adds this automatically to stop pasted code interfering with the forum site.