Check out the LimeSurvey source code on GitHub!
Welcome, Guest
Username: Password:

TOPIC: Adding Google Analytics

Adding Google Analytics 5 years 4 months ago #58619

  • medicnick
  • medicnick's Avatar
  • Offline
  • Junior Lime
  • Posts: 21
  • Karma: 0
It was not too difficult to add Google Analytics. It requires two steps.
1) Create a file named analyticstracking.php and save it in the root directory with this content replacing the UA=xxxxxxx-x with your own tracking code:
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-xxxxxxx-x']);
  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
2) Add this line near the top of your index.php file "require_once(dirname(__FILE__).'/analyticstracking.php');"

This is working for me but be forewarned that due to the require_once that if it cannot find the file, it may return a page error. There may be another way to code that to request_once or something similar but I don't know the optimal language here.

The administrator has disabled public write access.

Adding Google Analytics 5 years 4 months ago #58686

  • DenisChenu
  • DenisChenu's Avatar
  • Online
  • Moderator Lime
  • Posts: 9284
  • Thank you received: 1324
  • Karma: 384

Why don't put ui tracking directly in template ?

I think the best is to put the script at welcome.pstpl (first page for each survey) and in surveylist.pstpl (index page, without survey).

Assistance on LimeSurvey forum and LimeSurvey core developpement are on my free time (Say thanks ?).
A bug not reported is a bug not corrected. | Please, read the documentation | La doc en français à besoin de vous
The administrator has disabled public write access.

Adding Google Analytics 4 years 11 months ago #64849

  • Nickko
  • Nickko's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 2784
  • Thank you received: 365
  • Karma: 78
I'm looking for the same think, thank's Shnoulle.

Edit : I go to inserte GA code in endpag.pstpl
Ergonome / Usability expert
Last Edit: 4 years 11 months ago by Nickko.
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.306 seconds
Imprint                   Data Protection Statement                  Revocation information and revocation form