For analytics or any markup that you add using the SDL Tridion, you want to validate the content model, authors, and think about how content and templates can evolve.
Content Model
Assuming there is one instance on all pages, you can add ( for Google ) to your page template:
<script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-XXXXX-Y']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); </script>
Authors
Authors will be developers in this case. But if you have SEO authors and several publications, consider adding a script template through the template, but the tracking code in the component field referenced by your TBB layout:
_gaq.push(['_setAccount', '@@ GoogleTrackingCode@ @']);
It's up to you how to add GoogleTrackingCode to the package. Adjust the rendering environment or template approach as needed.
Changes
If the script format can change often (doubt), consider the component fields for the script itself. Most likely, the business will want more detailed tracking of links and campaigns.
Detailed tracking
To add tracking codes for individual links ( Original links ) or custom tracking , place either on the page template (for non-animated embedded component presentations) or in CT. Just remember that components are not unique in their own right .
source share