facebook/wordpress — pull request #345 by niallkennedy (2012-12-05 18:20:54+00:00)
Title: track Facebook social actions in Google Analytics

Add support for [Google Analytics social action tracking](https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingSocial) for like, send, and comment actions. Currently supports the two most popular Google Analytics plugins in the WordPress plugin directory -- [Google Analyticator](http://wordpress.org/extend/plugins/google-analyticator/) and [Google Analytics for WordPress](http://wordpress.org/extend/plugins/google-analytics-for-wordpress/) -- through actions and filters specific to the Google Analytics loader of each plugin.

This pull request also adds support for JavaScript function queueing, allowing other plugins to queue up JavaScript code for execution during or after execution of the `fbAsyncInit()` function by the Facebook JavaScript SDK. Plugins could previously add JavaScript code inside the `fbAsyncInit()` function through the `facebook_jssdk_init_extras` filter fired during enqueue scripts action priority 1. Functions added to the queue after it is has been flushed by `fbAsyncInit()` will be executed immediately.

Example: `FB_WP.queue.add(alert("Hello world"));`

Our JavaScript iterates through all Google Analytics trackers registered for the page, recording the social action on each.

[Google Analytics social action tracking](https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingSocial) supports arbitrary values for `network` and `socialAction` parameters. Our JavaScript uses the same values as the [Google Analytics social tracker sample code](https://code.google.com/p/analytics-api-samples/source/browse/trunk/src/tracking/javascript/v5/social/ga_social_tracking.js) for Facebook, adding comment create and destroy values.

FB.Event.subscribe	socialAction

edge.create	like

edge.remove	unlike

message.send	send

comment.create	comment

comment.remove	uncomment

The `opt_target` value is always the URL of the page receiving the action.

## Broader use

Google Analytics might be initialized by [ga.js](https://developers.google.com/analytics/devguides/collection/gajs/), the new [analytics.js](https://developers.google.com/analytics/devguides/collection/analyticsjs/), a [DoubleClick dc.js](http://support.google.com/analytics/bin/answer.py?answer=2444872), a locally-hosted file, or other means. If your JavaScript can act on the `_gaq` queue and registers trackers through `_gat` it should be compatible with this included JavaScript.

## Including other WordPress Google Analytics plugins

Each Google Analytics plugin has its own preferences and approach to determine if Google Analytics should be included on the page. It's not enough to simply detect the existence of the loaded plugin: we want to only attach extra code when Google Analytics has been loaded. Google Analytics plugins for WordPress might vary inclusion based on a sampling (due to Google Analytics rate limiting or other reasons), off for logged-in users, off based on a preference set in plugin settings, or other reasons. This pull request purposely ties into filters and actions of the plugins to only load our add-ons when the add-on target is known to exist on the page.