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?
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.
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.)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.