Jump to content

Adding Mixpanel, Heapanalytics javascript code to header.tpl


Recommended Posts

Hi

 

I am trying to add a few analytics suites to my Prestashop 1.6 install. I am using the default

template. I have tried adding the javascript code to the <head> portion of header.tpl file. I have tried adding it to the beginning of the head and the end of the header close to </head>.

 

I get errors and Prestashop fails to load.

 

Just for good measure I have tried to add the code for

Heapanalytics.com

Segment.io

Google Analytics (which I know a module exists)

 

It always ends in an error.

 

Here is one of the javascript code I am trying to add (one of them):

<script type="text/javascript">
window.heap=window.heap||[];heap.load=function(a){window._heapid=a;var b=document.createElement("script");b.type="text/javascript",b.async=!0,b.src=("https:"===document.location.protocol?"https:":"http:")+"//cdn.heapanalytics.com/js/heap.js";var c=document.getElementsByTagName("script")[0];c.parentNode.insertBefore(b,c);var d=function(a){return function(){heap.push([a].concat(Array.prototype.slice.call(arguments,0)))[spam-filter],e=["identify","track"];for(var f=0;f<e.length;f++)heap[e[f]]=d(e[f])};
heap.load("xxxxxxxxxxx");
</script>

 

The message I get is:

Fatal error: Uncaught exception 'SmartyCompilerException' with message 'Syntax Error in template "/home/aftensto/public_html/bergesolutions.com/shop/themes/default-bootstrap/header.tpl" on line 59 "function(){var a=Array.prototype.slice.call(arguments);return a.unshift(t),window.analytics.push(a),window.analytics[spam-filter];for(var" unknown function "function"' in /home/aftensto/public_html/bergesolutions.com/shop/tools/smarty/sysplugins/smarty_internal_templatecompilerbase.php:667 Stack trace: #0 /home/aftensto/public_html/bergesolutions.com/shop/tools/smarty/sysplugins/smarty_internal_templateparser.php(2900): Smarty_Internal_TemplateCompilerBase->trigger_template_error('unknown functio...') #1 /home/aftensto/public_html/bergesolutions.com/shop/tools/smarty/sysplugins/smarty_internal_templateparser.php(3101): Smarty_Internal_Templateparser->yy_r153() #2 /home/aftensto/public_html/bergesolutions.com/shop/tools/smarty/sysplugins/smarty_internal_templateparser.php(3201): Smarty_Internal_Templateparser in /home/aftensto/public_html/bergesolutions.com/shop/tools/smarty/sysplugins/smarty_internal_templatecompilerbase.php on line 667

 

I have attached a screenshot of the error.

 

post-19263-0-70465000-1401166766_thumb.png

Link to comment
Share on other sites

analytics code (and other scripts based on js) usually uses brackets { } 

these chars are a part of smarty syntax.

this is why you have to use {literal}{/literal} tags to inform compiler that code between {literal} CODE {/literal} tags arent a smarty syntax

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...