Add Google Analytics Code to your drupal 7 in 3 steps

Sun, 02/19/2012 - 14:23 -- meladawy

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

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")+""; 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

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.