In Our Drupal World there is a lot of modules that can help us in different purposes. Google Analytics is one of the most important modules that help you to integrate your drupal web application with Google Analytics using some GUI configurations. But if you are looking for performance you should reduce the number of installed modules, Thats why we are going to Explain how to Integrate google Analytics Code to your Drupal web applications Easly in 3 Steps by using "drupal_add_js()" function .
1- Open your "page.tpl.php" file from your theme directory "sites/all/themes/XXX/page.tpl.php" or "themes/XXX/page.tpl.php" where XXX is your theme name.
2- Add the following Code at the top of "page.tpl.php" file
<?php drupal_add_js('var _gaq=[["_setAccount","XX-XXXXXXXX-X"],["_trackPageview"]];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.async=1; g.src=("https:"==location.protocol?"//ssl":"//www")+".google-analytics.com/ga.js"; s.parentNode.insertBefore(g,s)} (document,"script"));' , array('type' => 'inline', 'scope' => 'footer', 'weight' => 2)); ?>
3- Replace XX-XXXXXXXX-X with the Id of your Google Analytics Account
Add new comment