Viewing 6 replies - 1 through 6 (of 6 total)
  • Hi,

    Here’s an example of tracking code customization;

    https://gist.github.com/deconf/db063aaea21974531c0bc42b502529a2

    Thanks Alin. I need this too.

    Any chance of a bit more info about updating that code?
    Before using GADWP I was doing this in functions.php with
    ga('set', 'userId', <?php echo get_current_user_id(); ?>);

    Not quite sure how to use your code below correctly….?

    /* Analytics Code */
    function gadwp_addcode($gadwp) {
    	$commands = $gadwp->get(); // Get commands array
    	
    	array_pop($commands); // Pop the last element
    	
    	$fields = array();
    	$fields['hitType'] = 'pageview';
    	$commands[] = $gadwp->prepare( 'send', $fields ); // Add a new line to the commands array
    	
    	$gadwp->set($commands); // Store the new commands array
    }
    add_action( 'gadwp_analytics_commands',  'gadwp_addcode', 10, 1 );

    Here you go:

    /* 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 );
    • This reply was modified 8 years, 8 months ago by Alin Marcu.

    Thanks so much Alin, that’s it! All working. Appreciate your help. Hopefully this will help lots of people in the future that need to add the UserID in WordPress/GADWP/Google Analytics.

    Do I still need to add ga(‘set’, ‘userId’, {{USER_ID}}); to my header.php template?

    You should add this in as a checkbox. Awesome!

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Does plugin support Universal Analytics/UserId’ is closed to new replies.