How to implement Google Analytics on SDL tridion websites?

My parameters:

  • Include analytics code in page templates or CT.

  • create a component containing the analytic code and display it in the Comonent presentation page.

which could be better or please offer any other way.

+4
source share
2 answers

The first approach is usually preferable because it allows you to include information about a component or page in your call to Google Analytics. And you may not even have to write it yourself, as there is a free extension called Web Analytics Enabler, which is available here . I recommend you check this out first.

+8
source

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 .

+3
source

All Articles