Skip to content

Instantly share code, notes, and snippets.

@jdeeburke
Last active September 6, 2018 22:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdeeburke/3dcb15bc3b785e791a6161d72a6e32f3 to your computer and use it in GitHub Desktop.
Save jdeeburke/3dcb15bc3b785e791a6161d72a6e32f3 to your computer and use it in GitHub Desktop.
WooCommerce Google Analytics Pro Social Login Integration
<?php
/**
* Tracks a social login authentication event with Google Analytics Pro.
*
* @param int $user_id the ID of the user that was just authenticated
* @param string $provider_id the social login provider ID that authenticated the user e.g. `facebook`
*/
function sv_wc_google_analytics_pro_track_social_login_authentication( $user_id, $provider_id ) {
// event name
$event_name = 'social login authentication'
// event properties -- see https://developers.google.com/analytics/devguides/collection/analyticsjs/events for more details
$properties = array(
'eventCategory' => 'category',
'eventAction' => 'action',
'eventLabel' => 'label',
'eventValue' => 100,
);
// additional enhanced ecommerce data to send with the event -- will have to read the code for more details on this param.
$ec = array();
// (optional) identities to use when tracking the event - if not provided, auto-detects from GA cookie and current user.
$identities = array();
// true/false -- whether the event is an admin event or not
$admin_event = false;
wc_google_analytics_pro()->get_integration()->api_record_event( $event_name, $properties, $ec, $identities, $admin_event );
}
add_action( 'wc_social_login_user_authenticated', 'sv_wc_google_analytics_pro_track_social_login_authentication', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment