Reputation: 14544
The website has a registration form, and when the user submits their personal details it creates an account for them and the page is reloaded for them to continue with additional form fields. At this point we have a user ID for them from our own users database table.
How can we track this in Google Analytics, to say that user (ID 12345 according to our database) has registered?
It has been a couple of years since I used GA (when it was ga.js) other than just adding the tracking code. How do I achieve this in the current Universal Analytics?
Upvotes: 2
Views: 754
Reputation: 2912
I've done something similar with Custom Event Tracking using Google Analytics.
if((typeof ga == 'function')) {
ga('send', 'event', 'Register', 'user', 'User ID', <?php echo $user->id; ?>, {
nonInteraction: true
});
}
In your case, you want to make sure it only fires off when the page is being submitted:
<?php if(($_SERVER['REQUEST_METHOD'] == 'POST')): ?>
if((typeof ga == 'function')) {
ga('send', 'event', 'Register', 'user', 'User ID', <?php echo $user->id; ?>, {
nonInteraction: true
});
}
<?php endif; ?>
You can put this anywhere in the page after the point where you've initialized your GA.
Upvotes: 1
Reputation: 34591
Basically, you do it like this:
ga('create', 'UA-XXXXX-Y', { 'userId': 12345 });
ga('send', 'pageview');
(Remember to replace UA-XXXXX-Y
with your own Tracking ID.)
General information about the User ID feature
Upvotes: 0