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.
[SOLVED] Google Analytics - New Version Causing Problems
-
- Forum Members
- Posts: 125
- Joined: Tue Nov 22, 2011 2:22 pm
Re: [SOLVED] Google Analytics - New Version Causing Problems
@Velden, thanks, great suggestion, just tried this on one of the sites we run
Added an extra space at the end of the GA code to test it, and it stripped it out nicely.
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}
Going up, woop, woop.
-
- Forum Members
- Posts: 125
- Joined: Tue Nov 22, 2011 2:22 pm
Re: [SOLVED] Google Analytics - New Version Causing Problems
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.
Going up, woop, woop.