How to add Google Analytics code to Drupal 7

How To Add Google Analytics Code To Drupal 7

We Are Going To Discuss About How to add Google Analytics code to Drupal 7. So lets Start this Article.

Open the folder modules/system in your Drupal set up, then copy html.tpl.php file to your theme’s listing. Add the code you want to the file and save.

Don’t overlook to clear the cache.

On a Drupal web site, you need to insert further javascript utilizing the drupal_add_js operate contained in the THEME_preprocess_html operate within the template.php file. Doing so permits you to correctly cache your web site. Specifically, that is how it will look:

    operate THEME_preprocess_html(&$variables) {

      $ga  = "var _gaq = _gaq || [];n";
      $ga .= "_gaq.push(['_setAccount', 'UA-XXXXXXX-X']);n";
      $ga .= "_gaq.push(['_setDomainName', '']);n";
      $ga .= (*7*);
      $ga .= "(function() {n";
      $ga .= "  var ga = document.createElement('script'); ga.type="textual content/javascript"; ga.async = true;n";
      $ga .= "  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '';n";
      $ga .= "  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);n";
      $ga .= "})();n";

      drupal_add_js($ga, array('kind' => 'inline', 'scope' => 'header'));

Be certain to substitute the UA ID and web site title with your individual. Also, make sure to rename THEME to your theme and clear the cache when full.

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Leave a Reply

Your email address will not be published. Required fields are marked *