While sending Google information that is personally identifiable is simply not permitted, you can instead send an identifier which is known only to you.
You should create what I’m going to term a “Google Analytics identifier” (GAID) which is mapped to the username/user ID and is only used to send tracking data to Google Analytics. You’ll likely need to store this against the user object/user table in your backend system.
I've written up some real world examples of what is and isn't allowed in this blogpost:
Identifying your users in Google Analytics while complying with section 7 of the terms of service
You can then send something like this to Google Analytics:
var gaid = 'some secret identifier';
_gaq.push(['_setCustomVar', 1, 'gaid', gaid, 1 ]);
This means set a custom variable (1st parameter is '_setCustomVar'
)...
- in slot
1
(2nd parameter)
- named
'gaid'
(3rd parameter)
- with value
'some secret identifier'
(4th parameter)
- for the entire visit (5th parameter)
Once this is done, you'll need to lookup each user against the gaid
in your backend system.
Alternatively, you could build your own integration against the Google Analytics API to combine the data from Google Analytics with the data in your backend system.
If you change the content of a visit based custom variable after it is initially set, but in the name visit, the value will be overwritten.
Update:
On your website
Google released Universal Analytics out of beta at the start of April 2014. Now it's fairly easy to setup this kind of thing with the User ID feature
e.g.
<script>
// Standard Google Universal Analytics code
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXXX-Y', {'userId': gaid});
ga('set', 'dimension1', gaid); // Set a `Custom User ID` dimension too if the user id hasn't been rolled out to you yet.
ga('send', 'pageview');
</script>
The "User ID" feature is currently being rolled out, so in the meantime, we're using a Custom Dimension to store our own "Custom User ID".
In Google Analytics
- Browse to Google Analytics Administration
- Select an Account and then a Property within that account
- Expand Custom Definitions below a selected Property
- Select Custom Dimensions
- Click on the Custom Dimension Name button
- In the Add Custom Dimension screen
- Type Custom User ID in the Name field
- Select Visit from the Scope dropdown menu
- Check the Active checkbox
- Click the Create button
Congratulations, you now have a Custom Dimension named Custom User ID which is available for use within the Google Analytics interface. Next, you'll need to populate this custom dimension with some data.