Local Analytics v1.2.2

Local Analytics is a WordPress plugin for integrating Google Analytics, the free web analysis service by Google, into your Word Press powered blog.  The plugin is highly configurable and also allows caching of the urchin.js ga.js file locally, inorder to enable faster loading of pages. The plugin is based on my PHP program for speeding up Google Analytics by hosting it locally.

The plugin is highly configurable, yet simple. A normal user only needs to specify his / her Analytics UID, while advanced users can completely configure the behavior of the plugin.

Features

  • Highly configurable
  • Compatible with latest Google Analytics Code Update [NEW]
  • Supports local caching of urchin.js for fast loading of pages.
  • Supports compression of the local javascript files using mod_gzip.
  • Includes support for tracking Adsense and YPN ad clicks [NEW]
  • Includes support for tracking email links, external links and file downloads.
  • Includes support for tracking subdomains and main domain in a single profile.
  • Includes support for tracking visits to Admin Panels.
  • Includes support for tracking logged in users.
  • Includes uninstaller for complete removal of the plugin (I’m sure that you won’t be using it 🙂 ).

Advantages of Caching

  • Webpage loads faster, since user’s browser can use the existing connection with your web server to download the file and doesn’t need to create a new connection to Google’s server.
  • Sometimes, though very rarely, google servers become overloaded and your page load time will be affected drastically.
  • Some ad blockers are now blocking tracking services like Google Analytics. This script will be a work around to that too.

Screenshot

Here is a screenshot of the Options page  of the plugin.

[Screenshot] Local-Analytics

Requirements

Installation

  1. Download, unzip & upload the plugin to your ‘/wp-content/plugins/’ directory.
  2. Activate the plugin through the ‘Plugins’ menu in WordPress.
  3. On plugin activation, it will automatically try to create  a file named local-urchin.js in the plugin directory. If it fails, you will see a notification message in the Admin Panel. In that case you will have to manually create the file and chmod it 666.
  4. Go to Options > Local Analytics and enter your Google Analytics UID and hit the Save Options button.

Upgrade

I recommend uninstalling the current plugin (using the uninstall button in Options > Local Analytics) and installing the new version.

Download

Current stable version of the plugin is v1.2.2.

You can download the plugin from the WordPress Plugin Repository.

Frequently Asked Questions

  1. Q. Google Analytics says that the code is not installed correctly. Is something wrong?
    A. Check whether you are seeing any error message in your Admin Panel. If so, fix it. Else ensure that Disable Local Analytics tracking option is unchecked in the Options page.
  2. Q. I am getting the following error in my pages. What should I do?
    Warning: eregi(): REG_EMPTY in /private/path/replaceforprivacy/wp-content/plugins/local-analytics/local-analytics.php on line 127
    A. Using the plugin in non www domains caused the warning in pre 1.12 versions. Please upgrade to the latest version. You have to uninstall the current plugin before upgrading. Alternatively, you may edit the Internal Domains field to fix the error.
  3. Q. I installed the plugin successfully. But I am getting the following error in my Admin Panel
    local-urchin.js does not exist. Please create it.
    A. The plugin automatically downloads and stores a fresh copy of urchin.js ga.js in the plugin directory, under the filename local-urchin.js. While activating the Local Analytics, if there are sufficient privilages, the plugin will automatically create the file. If it fails, then you will have to manually create the file and chmod it 0666. The best idea is to chmod the plugin directory 0666, before activating the plugin (so that the file will be created automatically on plugin activation).
  4. Q. I installed the plugin successfully. But I am getting the following error in my Admin Panel
    local-urchin.js is not writable. Please chmod it 666.
    A. See FAQ entry #4.
  5. Q. How can I chmod a file?
    Q. How can I change file permissions?

    A. You can chmod / change file permission using your FTP client. But the steps are different for different FTP programs. In most FTP clients, you can chmod a file by choosing the option Properties  from the right click context menu.  Also checkout this article by Stadtaus.com on changing file permission in 5 popular FTP clients.
  6. Q. Will Local Analytics integrate the Google Analytics reports within the WordPress Administration Panel?
    A. It is not possible with Local Analytics. But David Szpuner had pointed out an excellent plugin called WordPress Reports by TanTan, which allows you to integrate your Google Analytics and FeedBurner stats within your Admin Panel.
  7. Q. How can I check whether the plugin is installed correctly or not?
    A. After activating the plugin, visit your blog and check the source of the page for the Local Analytics code. A sample code is given below.
    <!– Begin Google Analytics Code by Local Analytics Plugin –>
    <script type='text/javascript' src='http://www.domain.com/wp-content/plugins/local-analytics/local-urchin-js.php?ver=1.0′></script>
    <script type='text/javascript'>
    _uacct = "UA-XXXXXXX-X";
    urchinTracker();
    </script>
    <!– End Google Analytics Code by Local Analytics Plugin –>

    <!-- Begin Google Analytics Code by Local Analytics Plugin -->
    <script type='text/javascript' src='http://www.domain.com/wp-content/plugins/local-analytics/local-urchin-js.php?ver=1.0'></script>
    <script type="text/javascript">
    var pageTracker = _gat._getTracker("UA-XXXXXX-X");
    pageTracker._initData();
    pageTracker._trackPageview();
    </script>
    <!-- End Google Analytics Code by Local Analytics Plugin -->
  8. Q. I have activated the plugin. But I can’t find the Local Analytics code in my page source. What is the problem?
    A. First of all, ensure that the plugin is installed and configured correctly. If it not configured correctly, then you will see a notifcation message in your WordPress Admin Panel.
    If it is configured correctly, then ensure that the option “Disable Local Analytics tracking” is disabled and logout of your WordPress account, refresh your blog’s homepage (use CTRL + F5 to ensure that the page was not loaded from your browser cache) and check for the Local Analytics code in your page source.
    Please keep in mind that when you are logged in, your visits will be tracked only if you have enabled the “Track Users” option and have appropriate value set for the option “Max. Tracked User Level “.
  9. Q. I have another question that is related / not related to Local Analytics. What should I do?
    Q. My question is not answered above. What should I do?

    A. Either post your question as a comment below or contact me. I will try my best to help you solve it.

ChangeLog

  • v1.2.2
    • Changed relative reference to astrack.js with absolute reference to make the plugin compatible with blogs with different site and wordpress location.
  • v1.2.1
    • Minor update. Fixed a mistake in gzip compression, as pointed out by Sergey Biryukov
  • v1.2
    • Updated the plugin to make it compatible with latest Google Analytics code update
    • Added Adsense and YPN click tracking
  • v1.1.3
    • Fixed a minor error which caused a Bad arguments  warning when the Internal Domains field was left empty.
  • v1.1.2
    • Fixed an error which caused a REG_EMPTY warning in non www domains
  • v 1.1.1
    • Corrected a typo in error message
  • v 1.1
    • Fixed the error pointed out by Kevin
    • Removed the onclick events from RSS feed
    • Dropped domain name from tracked downloads
    • Edited admin panel to display configuration errors

138 comments

  1. Joyce, thank you for this great plugin! I’ve been using it for a month, and just today I see this error (using WP 2.3.3 and K2 theme):
    Warning: parse_url(http://) [function.parse-url]: Unable to parse URL in /home/[my directory]/public_html/blog/wp-content/plugins/local-analytics/local-analytics.php on line 123.

    Line 123:
    $url = parse_url($url);

    The URL for the page on which it appears is http://www.coreknowledge.org/blog/

    but http://www.coreknowledge.org/blog/index.php is OK.

    I’ve never seen this problem before today, and there have been no changes to the website, other than a WordPress update from 2.3.2 to 2.3.3.

    Ideas? For now I’ve disabled the stats.

    —Diana

    1. Maybe we need some code in function locan_parse_link to cope with the missing index.php? I’d rather not add a rewrite mod to .htaccess to force index.php, that might cause other problems. It’s odd that this worked fine for so long, and then failed. Something about the server configuration perhaps? I’m on shared hosting, so who knows! Just need a little patch perhaps?

      1. Oddly, the problem has returned, with no changes to the blog code, and does not seem to have any relationship to whether the URL contains index.php or not. I deactivated and reactivated the plugin, and the problem disappeared. Weird.

    2. OK, I hope this helps someone else!

      Check if your wp-config.php has extra linefeeds after the closing bracket, and remove them.

      It messes up the loading order of scripts for the page. It was affecting my tinyMCE visual editor once, and now I find it was affecting this parse_url as well.

      Fantastico will insert extra linefeeds in wp-config.php if you use it to update.

      —Diana

  2. Hi Joyce,

    Local Analytics does not support WordPress 2.5, it crashes on activation. When can the community expect an updated version of this great plugin.

    We <3 Local Analytics 🙂

  3. Pingback: Eric
  4. Hi Joyce – I have uninstalled your plugin, but it has left some code in my template, which is generating javascript errors. I am new to wordpress.

    Would you mind emailing me about how to remove this bit of script from my site?

    <!–
    google_ad_client = “pub-0909510381367095”;
    /* 336×280, created 4/13/08 */
    google_ad_slot = “7189509193”;
    google_ad_width = 336;
    google_ad_height = 280;
    //–>

  5. Hello Derek

    Derek Martin :

    Hi Joyce – I have uninstalled your plugin, but it has left some code in my template, which is generating javascript errors. I am new to wordpress.

    Would you mind emailing me about how to remove this bit of script from my site?

    <!–
    google_ad_client = “pub-0909510381367095″;
    /* 336×280, created 4/13/08 */
    google_ad_slot = “7189509193″;
    google_ad_width = 336;
    google_ad_height = 280;
    //–>

    Hello Derek,

    The Javascript code quoted above is Google Adsense ad code. It was not added by Local Analytics. If you have any plugin related with Google Adsense, remove it and check your page source again. If that doesn’t help, feel free to contact me again 🙂

    Joyce

  6. Joyce,
    The Google Analytics Code is showing up in the Source view but it appears I have an open script:
    <script type=\\\\\\\”text/javascript\\\\\\\”>
    try {
    var pageTracker = _gat._getTracker(\\\\\\\”UA-6204359-10\\\\\\\”);
    pageTracker._trackPageview();
    } catch(err) {}</script>
    pageTracker._initData();
    pageTracker._trackPageview();
    </script>

    The result is this line at the top of the blog page:
    pageTracker._initData();pageTracker._trackPageview();

    I checked the coding of the plug-in but couldn’t find the problem. (The real problem
    is I’m old and I don’t want to learn new coding like JS and PHP… ‘Cause it gives
    me a headache.)

    Thanks for your help.
    ~ Steve

Comments are closed.