I need to add some enhanced ecommerce tags to standard Google Analytics tracking on few pages. I think the best way to do it would be to use Joomla Custom fields so I created a custom field for testing:
The custom field is:
ID: '1'
Name: 'ec-js'
Automatic display - off
type: text filter: no
Show on: both
value (in one article; for testing): 'ga('require', 'ec');'
The template is Yootheme Infinite (Warp 6 based). I put the custom code in 'template.php', not in article override because I need it on every page including /search, categories etc.
I have gone through Joomla Docs but I'm a beginner...ATM I have:
Top of the page php:
Code: Select all
<?php
JLoader::register('FieldsHelper', JPATH_ADMINISTRATOR . '/components/com_fields/helpers/fields.php');
$jcFields = FieldsHelper::getFields('com_content.article', $item, True);
foreach($jcFields as $jcField)
{
$jcFields[$jcField->name] = $jcField;
}
?>
Code: Select all
<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-xxxx', 'auto');
ga('require','displayfeatures');
<?php echo $article->jcFields['ec-js']->value; ?>
ga('send', 'pageview');
</script>
The problem is that the contents of the custom field are not displayed on the test page containing the field value - the override is clearly not working, something is definitely missing
Help with this would be appreciated.
Many thanks.