Jump to content

Add custom php and js in tpl file


Recommended Posts

Hi guys,

 

I want to add google analitycs manually in prestashop 1.7 but i dont know how to add custom php and js in tpl files.

 

I tried to add the js code in javascript.tpl and the php code in layout-both-columns.tpl just after the <body> markup.

 

For js between the foreach there : 

{foreach $javascript.external as $js}
<script type="text/javascript" src="{$js.uri}" {$js.attribute}></script>
{/foreach}

And the php like that :

{php}
<?php include_once("analyticstracking.php") ?>
{/php}

But nothing work ^^

 

Please need some help :)

 

Thanks you

Link to comment
Share on other sites

To add JS code in /themes/classic/templates/_partials/javascript.tpl i had to add literal markup wrap around script:

{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','https://www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-XXXXXXX-1', 'auto');
ga('send', 'pageview');

</script>
{/literal}

Any easy way to add the php to finish google analytics implementation?

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...