Skip to content

Instantly share code, notes, and snippets.

@deconf
Last active March 15, 2018 19:28
Show Gist options
  • Save deconf/23cbc2b169c8334edef2ed4d54de3cd6 to your computer and use it in GitHub Desktop.
Save deconf/23cbc2b169c8334edef2ed4d54de3cd6 to your computer and use it in GitHub Desktop.
Adds userId support for Universal Analytics in GADWP
/* Analytics Code */
function gadwp_addcode( $gadwp ) {
$commands = $gadwp->get(); // Get commands array
$fields = array();
$fields['option'] = 'userId';
$fields['value'] = get_current_user_id();
if ( $fields['value'] ){
$command = array( $gadwp->prepare( 'set', $fields ) );
array_splice( $commands, -1, 0, $command ); //insert the command before send
}
$gadwp->set( $commands ); // Store the new commands array
}
add_action( 'gadwp_analytics_commands', 'gadwp_addcode', 10, 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment