Artículo en español: Comprobar el marcado de Google Analytics y Nielsen
In this post we analyse how to check that we’ve set correctly the Google Analytics and Nielsen tracking code (or others with a litle changes).
To do this we’ll use php and a sitemap from the website we want to check.
CheckTracking allows us to check automaticaly that we’ve set correctly the Google Analytics and Nielsen tracking code.
Until the script is not connected directly to a web spider, we need to pass a sitemap to the php script. This script reads the sitemap, load each url and search for the Google Alnalitics and Nielsen SiteCensus tracking code.
On finish, it shows an html table report with the detail of each sitemap url.
Nowadays (Version 0_0 ) it shows:
- Header status: ok/302/404
- Google Analytics (classic version – no ajax):
- If the tracking code is included.
- Account key.
- Nielsen SiteCensus:
- If the tacking code is included.
- ContentGroup var: _rsCG
- Script version: Example: src=»//secure-uk.imrworldwide.com/v53.js
We can copy and paste this report to an excel to work with the data (segment, filter, etc..).
Stage 1: Pre-requisites
- A sitemap http://www.sitemaps.org/
- Apache web server.
Stage 2: Publish the sitemap
We assume on this post that the sitemap is on the url: http://www.misitio.com/sitemap.xml
Stage 3: Upload files to web server
In version (V 0.0) we have two files:
- check_tracking_lib.php: file that allow us to load an url and check if the analytics codes are included without errors. We will edit this file to include/adapt/add/improve the functions and search for new analytics trackings codes (at this time it only search for Google Analytics and Nielsen SiteCensus)
- sitemap_lib.php: this file reads a sitemap and extracts the urls on it. At this time it mades a call to the check_tracking_lib.php and returns if each url has the tracking code included.
Stage 4: Load the sitemap
At this point we need to pass the sitemap url to the sitemap_lib.php script.
If we assume the files are on the dir http://www.misitio.com/checktracking/ we’ll call:
If we only want to check one url:
Stage 5: Check the report
After load a sitemap url, the result the appears on the report.
On finish the last one, we shall copy all the report and paste it on an excel file(improve this is one of the TODO’s).
At this point we can segment, search or work with data more efficiently.
- Clean and improve code.
- Separate content from presentation. Create informe.php to send a sitemap and call sitemap_lib.php and check_tracking_lib.php to check that tracking code is include withouth errors.
- Check that the asyncronous Google Analytics code is included (Include the function in check_tracking.php).
- Allow to connect a botspider and create «on the fly» report.
- Check other analytics codes.
- Improve presentation.
- Allow to export to CSV or Excel.
- Check security and XSS errors.
Download CheckTracking Analytics y Nielsen (zip – 1,4MB)
- Apache web server: http://www.apache.org/
- cURL: http://curl.haxx.se/
- cURL alternatives to download html files: http://www.php-mysql-tutorial.com/wikis/php-tutorial/reading-a-remote-file-using-php.aspx
- Read sitemaps.xml from php: http://debuggable.com/posts/parsing-xml-using-simplexml:480f4dfe-6a58-4a17-a133-455acbdd56cb
- Regular expressions: regexps PCRE http://www.php.net/manual/es/reference.pcre.pattern.syntax.php
- Yoast: GreaseMonkey statistics detector: http://yoast.com/tools/seo/greasemonkey/statistics-detector/
Creative Commons 3.0 , so you can edit and improve what you want while this license is respected (If you made a comment or share your work, even better)