WordPress Plugin: Google Analytics Internal

Google Analytics gathers lots of data when users interact with your site from the front end, but sometimes you need to match this with actions taken in WordPress.

This plugin triggers a custom event in Google Analytics when a post is published and updated and when a comment it submitted and approved. That way you can monitor any relationship between publishing and changes in traffic.

That’s it at the moment. If there are other events you would like to track or any improvements, let me know in the support forums or even better on GitHub.

If you already have Yoast’s Google Analytics for WordPress installed and configured, you don’t need to do anything as the plugin should find you UA string automatically.

If you don’t have Yoast’s plugin, you can set your UA string in your wp-config.php:

define( 'DBISSO_GA_UA', 'UA-XXXXXXXX-Y' );

Configuration

Currently there is no GUI for the plugin, but you can use the dbisso_gai_event_actions filter to choose which events you want to be triggered and what the Google Analytics event action will be. For example:

add_filter( 'dbisso_gai_event_actions', 'custom_theme_filter_dbisso_gai_event_actions', 10, 1 );

function custom_theme_filter_dbisso_gai_event_actions( $actions ) {
    // Don't send 'update post' events
    $actions['update_post'] = false;

    // Change the action name that appears in Google Analytics
    $actions['publish_post'] = __( 'Publish Post' ),

    return $actions
}

There are currently four actions publish_post, update_posts, comment_submitted and comment_approved.

Changelog

0.3.0

  • Fix: Use Yoast_GA_Options to look for UA string supplied by Yoast’s Google Analytics for WordPress.
  • Deleting, trashing or unapproving a comment no longer triggers an event

0.2.0

  • Feature: Add tracking when a comment is posted or approved.
  • Introduce filter dbisso_gai_event_data to filter data just before event is sent.
  • Introduce filter dbisso_gai_event_actions to set the action strings for different WP.
  • Updates to posts are now have a separate action (‘Update Post’).
  • I18n for some strings.
  • Introduce DBisso_GoogleAnalyticsInternal_Event to manage the sending of events.
  • Add some basic unit tests
  • Include my name in copyright statement!

0.1.0

  • Initial release

Download the plugin now on WordPress.org.

It’s also available on GitHub