Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Smarty error when Google Analytics code is installed

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
terryjackson
Smarty n00b


Joined: 24 Feb 2018
Posts: 2

PostPosted: Sat Feb 24, 2018 6:02 am    Post subject: Smarty error when Google Analytics code is installed Reply with quote

Hi,

My website is working fine but when I add Google Analytics code between <header> and </header> tags and then website goes down.

header.tpl
<!DOCTYPE html>
<html lang="en">
<head>

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-11468xxxx-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', 'UA-11468xxxx-1');
</script>


Google Analytics Code
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-11468xxxx-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', 'UA-11468xxxx-1');
</script>

Website Error
[24-Feb-2018 00:58:01 America/New_York] PHP Fatal error: Uncaught --> Smarty Compiler: Syntax error in template "/home/xxxxxxxx/public_html/tmpl/header.tpl" on line 9 "function gtag(){dataLayer.push(arguments);}" - Unexpected ".", expected one of: "}" <--
thrown in /home/xxxxxxxx/public_html/inc/libs/smarty3/sysplugins/smarty_internal_templatecompilerbase.php on line 9

I am not developer of this script but this script is working 100% perfect without Google Analytics code. So when I add Google Analytics code then site goes down.

How to solve this error, help me please?


Terry
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Sat Feb 24, 2018 11:08 am    Post subject: Reply with quote

Place every foreign snippet into a separate template, wrapped into {literal}'s when necessary.
And {include} them from main template.
You can set a fixed cache_id to them to indicate that they can be heavily cached with little to no sideeffects.
Back to top
View user's profile Send private message
terryjackson
Smarty n00b


Joined: 24 Feb 2018
Posts: 2

PostPosted: Sat Feb 24, 2018 12:09 pm    Post subject: Reply with quote

AnrDaemon wrote:
Place every foreign snippet into a separate template, wrapped into {literal}'s when necessary.
And {include} them from main template.
You can set a fixed cache_id to them to indicate that they can be heavily cached with little to no sideeffects.


Thank you, your tip solved my problem. It looks you gave very basic information about using Smarty but since I never used Smarty earlier that's why I was stuck.

I just put Google Analytics code between {literal} {/literal} and it worked. Very Happy

Thanks

Terry
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP