Extension talk:Google Analytics Integration/Archive

NOTE - Please install new version
Please install the latest version! As seen below - The initial release of the extension was not returning 'true' properly, which causes errors in MW 1.11+ and halts further processing on the specified Hook in every version! (not cool)

I installed this extension on my MW 1.11(Alpha). Got Following error.
(Note I have removed my hosting a/c name and put XXXXX instead for obvious reason.)

MediaWiki internal error. Original exception: exception 'MWException' with message 'Detected bug in an extension! Hook googleAnalyticsHook failed to return a value; should return true to continue hook processing or false to abort.' in /home/XXXXX/public_html/wiki/includes/Hooks.php:133 Stack trace: Exception caught inside exception handler: exception 'MWException' with message 'Detected bug in an extension! Hook googleAnalyticsHook failed to return a value; should return true to continue hook processing or false to abort.' in /home/XXXXX/public_html/wiki/includes/Hooks.php:133 Stack trace: MonoBookTemplate->execute('MonoBookTemplat...', Array)
 * 1) 0 /home/XXXXX/public_html/wiki/skins/MonoBook.php(225): wfRunHooks
 * 2) 1 /home/XXXXX/public_html/wiki/includes/SkinTemplate.php(463): MonoBookTemplate->execute('MonoBookTemplat...', Array)
 * 3) 2 /home/XXXXX/public_html/wiki/includes/OutputPage.php(683): SkinTemplate->outputPage
 * 4) 3 /home/XXXXX/public_html/wiki/includes/Wiki.php(301): OutputPage->output(Object(OutputPage))
 * 5) 4 /home/XXXXX/public_html/wiki/index.php(90): MediaWiki->finalCleanup
 * 6) 5 {main}
 * 1) 0 /home/XXXXX/public_html/wiki/skins/MonoBook.php(225): wfRunHooks
 * 2) 1 /home/XXXXX/public_html/wiki/includes/SkinTemplate.php(463):
 * 1) 2 /home/XXXXX/public_html/wiki/includes/OutputPage.php(683): SkinTemplate->outputPage
 * 2) 3 /home/XXXXX/public_html/wiki/includes/Exception.php(86): OutputPage->output(Object(OutputPage))
 * 3) 4 /home/XXXXX/public_html/wiki/includes/Exception.php(111): MWException->reportHTML
 * 4) 5 /home/XXXXX/public_html/wiki/includes/Exception.php(191): MWException->report
 * 5) 6 /home/XXXXX/public_html/wiki/includes/Exception.php(225): wfReportException
 * 6) 7 [internal function]: wfExceptionHandler
 * 7) 8 {main}

-Gautam
 * Thx! The posted code should be working now.

runonloadhook
Tim, thanks for making this great extension. If you look at the code of any page in MW, you'll see near the end: if (window.runOnloadHook) runOnloadHook; Wouldnt using this hook (if possible) be a better way because GA advises to use the code just before the body tag? This hook is about just before the body tag. --Kenny5 19:11, 2 September 2007 (UTC)


 * If you run this extension on 1.11alpha+, you'll notice that the GA code actually shows up BELOW that script line. I added a new hook to the core (SkinAfterBottomScripts) specifically designed for JS-powered analytics engines.  I talked to the guys over at Google regarding the tag placement and they said that as long as Google is receiving data, the tag placement is fine.  There are certain locations where the script will not be executed properly and that's why they say put it at the bottom.  Either way, if you get data in your GA reports, you're good - and once 1.11 comes out, the extension utilizes the new hook that puts the script tag at the absolute bottom of the page.
 * Ah I see, great then. I'll wait for the upgrades then. Thanks for all your research in this. And I just checked and am getting the data even with my 1.9.3 (should have mentioned before) so this is great. This extension is great, I didnt have to alter the internal files in any way (which is always the goal). thanks again --Kenny5 19:35, 2 September 2007 (UTC)

Bottom of page; older version
I installed this and the script is not at the bottom of the page--though fairly near it. I'm using version 1.8. Right now when I go to google analytics and click the "check status" button it says that the tracking code hasn't been detected. What I'm guessing is that the detection mechanism specifically is looking for this at the bottom of the page but that, regardless it is working. I hope!. Anyway, I'll verify by checking back with google analytics in a few days and see if they are gathering any datat. Then I'll report the results here. Thanks for the extension! --Matthew (76.27.82.88 04:33, 14 September 2007 (UTC))
 * Let me know if you don't receive any data within 48 hours of installing the extension. GA seems to be 2-3 days behind at all times.  It should work even though it's not at the bottom, I talked to the GA guys when I wrote the extension.  ;-)

New GoogleAnalytics script
Changing this part of the code will incorporate the new GoogleAnalytics script: $funcOutput = "\n". "var gaJsHost = ((\"https:\" == document.location.protocol) ? \"https://ssl.\" : \"http://www.\");\n". "document.write(unescape(\"%3Cscript src='\" + gaJsHost + \"google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E\"));\n". " \n". "\n". "var pageTracker = _gat._getTracker(\"" . $googleAnalytics . "\")\n". "pageTracker._initData;\n". "pageTracker._trackPageview;\n". " \n"; --Jdj 02:21, 28 December 2007 (UTC)
 * Implemented support for the new ga.js script in r29077. Thx for the note, I wasn't aware they had a new script available.  Also, check the code - f/ large string chunks like that, HEREDOC syntax is much cleaner.  ;-)  Tim Laqua talk 22:05, 30 December 2007 (UTC)

Version 2 Compatibility?
A few days ago I upgraded to version 2 with my mediawiki 1.11.2 and my gumax skin. Google analytics says that it recognizes the code but it seems weird because my traffic has died. I know that one person registered this morning and two other people simply visited (I asked them to visit). Yet 5 hours later still no traffic. I know it's not the Google Analytics delay because my blog is showing healthy traffic.

Is there a compatibility issue with something? Any suggestions? [Ed D April 1, 2008] ...this is not an April Fools joke.
 * Do you define $wgGoogleAnalyticsAccount after the require_once( ... ) line? In previous versions, I didn't initalize that variable, so you could define your account number anywhere.  Now, because the extensions initalizes $wgGoogleAnalyticsAccount to a blank string, you need to make sure that your assignment of $wgGoogleAnalyticsAccount is *after* the require_once( ... ) statement for this extension (as shown on the extension page).  If that's not the issue, the only other thing I can think of is the GA delay (24-48 hours) and maybe your Blog is granted a higher priority or something due to either high traffic or high pagerank?  I'm also not sure if there's any difference in stat lag based on what version of the GA script you're using.  2.0 of this extension is using the new GA script.  I know there are people using this version on MW 1.11.2, so it's certainly not an incompatibility issue. Tim Laqua talk 11:48, 2 April 2008 (UTC)

Turns my Main Page into log file
When I try to use this extension, it turns my Main Page into a log file that looks like the code in the php file. I've put the two php files in the right folder and pasted the script into localsettings.php along with my GoogleAnalytics id but it just doesn't seem to want to work for me. I am using MediaWiki 1.12 and the cavendish theme.