Summary: Add Google Analytics tracking code to wiki pages
Version: 2007-03-21
Prerequisites: PmWiki 2.1.0
Status: Stable
Maintainer: Petko

Questions answered by this recipe

  • How can I add Google Analytics tracking code to my site?


Adding the tracking code for Google Analytics is easy -- simply add the following into any local or group customization file, replacing the UA-CODE-1 with your Google Analytics tracking code:
(To have the analytics code at the end of the page instead of the beginning, use $HTMLFooterFmt instead of $HTMLHeaderFmt. -- Pm)

$HTMLHeaderFmt['analytics'] = "
  <script src=''
  <script type='text/javascript'>
    _uacct = 'UA-CODE-1';


New Google Analytics code (may 2015 ; replace UA-××××××-×)

$HTMLHeaderFmt['analytics'] = "
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),

  ga('create', 'UA-××××××-×', 'auto');
  ga('send', 'pageview');


Other Method

You could also just copy the code into the .tmpl file of your standard skin.


It's also possible to add the above <script> lines directly into a skin template file, but a site should only do one or the other.

See Also



See discussion at GoogleAnalytics-Talk

User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.