Overview
Kissmetrics provides robust cross-domain tracking capabilities that allow you to track user behavior across multiple domains and websites. Unlike cookie-based approaches that break when users move between domains, Kissmetrics uses person-based identification to maintain continuity of user sessions and behavior across your entire digital ecosystem.
Cross-domain tracking is essential when you have:
- Multiple marketing sites and product applications on different domains
- Separate checkout or payment domains
- Subdomain architectures where users navigate between them
- Third-party hosted content or services
How Cross-Domain Tracking Works
Kissmetrics uses a person-centric tracking model. When you identify a user with a unique identifier (like an email address or user ID), that identity is associated with all events across any domain where Kissmetrics is installed with the same API key.
Key Concepts
Person Identity: The unique identifier (email, user ID, etc.) that ties all events together across domains.
Anonymous Tracking: Before identification, Kissmetrics creates an anonymous ID stored in a cookie. This tracks the user within a single domain.
Identity Merging: When you call identify(), Kissmetrics merges the anonymous activity with the identified person, creating a complete activity timeline.
Implementation Steps
Step 1: Install Tracking Code on All Domains
Ensure the Kissmetrics tracking code is installed on every domain you want to track. Each domain should use the same API key.
<!-- Install on domain-a.com, domain-b.com, etc. -->
<script type="text/javascript">
var _kmq = _kmq || [];
var _kmk = _kmk || 'YOUR_SAME_API_KEY';
function _kms(u){
setTimeout(function(){
var d = document, f = d.getElementsByTagName('script')[0],
s = d.createElement('script');
s.type = 'text/javascript'; s.async = true; s.src = u;
f.parentNode.insertBefore(s, f);
}, 1);
}
_kms('//scripts.kissmetrics.io/' + _kmk + '.js');
</script>
Step 2: Identify Users Consistently
Use the same identifier across all domains when a user logs in or can be identified.
// On domain-a.com after login
_kmq.push(['identify', 'user@example.com']);
// On domain-b.com after login
_kmq.push(['identify', 'user@example.com']);
// The same email ties both sessions together
Best Practices for Identifiers:
- Use email addresses for B2C applications
- Use user IDs for B2B or when emails can change
- Ensure the identifier is available on all domains
- Make the identifier stable (doesn't change over time)
Step 3: Identify Early in the User Journey
Call identify() as soon as you know the user's identity:
// After successful login
function handleLogin(user) {
_kmq.push(['identify', user.email]);
// ... rest of login logic
}
// When user data is available on page load
if (window.currentUser) {
_kmq.push(['identify', window.currentUser.email]);
}
Step 4: Handle Logged-Out Users
For logged-out users moving between domains, they will be tracked as separate anonymous users on each domain until they identify themselves.
// On logout, clear the identity
_kmq.push(['clearIdentity']);
// This ensures the next user on the same device gets a fresh identity
Subdomain Tracking
For subdomains (e.g., app.example.com, blog.example.com), Kissmetrics automatically shares cookies across the root domain by default. However, you should still identify users consistently.
// Works automatically across:
// - www.example.com
// - app.example.com
// - blog.example.com
// Just ensure you identify with the same ID
_kmq.push(['identify', 'user@example.com']);
Advanced Use Cases
Tracking Pre-Login Activity
Connect anonymous browsing to identified users:
// User browses anonymously on domain-a.com
// Kissmetrics tracks with anonymous ID
// User clicks email link to domain-b.com and logs in
_kmq.push(['identify', 'user@example.com']);
// Now all previous anonymous activity on domain-a.com
// is connected to user@example.com
Multiple User Sessions
Handle scenarios where users switch accounts:
// User logs out
_kmq.push(['clearIdentity']);
// Different user logs in
_kmq.push(['identify', 'different-user@example.com']);
Third-Party Payment Processors
When users navigate to external payment sites:
// Before redirecting to payment processor
_kmq.push(['record', 'Initiated Checkout', {
'Order ID': order.id,
'Amount': order.total
}]);
// On return to your site
_kmq.push(['identify', user.email]);
_kmq.push(['record', 'Completed Purchase', {
'Order ID': order.id,
'Amount': order.total
}]);
Troubleshooting
Users Not Tracking Across Domains
Issue: User activity on domain-a.com doesn't connect to activity on domain-b.com.
Solutions:
- Verify the same API key is used on both domains
- Confirm
identify()is called with the same identifier on both domains - Check that identification happens before critical events
- Ensure users are actually logging in on both domains
Anonymous Sessions Not Merging
Issue: Pre-login behavior doesn't merge with post-login activity.
Solutions:
- Verify
identify()is called on the same domain where anonymous activity occurred - Check browser console for Kissmetrics errors
- Ensure cookies aren't being blocked
- Confirm the user's browser allows third-party cookies if needed
Identity Persisting After Logout
Issue: New users see previous user's data.
Solutions:
// Always clear identity on logout
function handleLogout() {
_kmq.push(['clearIdentity']);
// ... rest of logout logic
}
Testing Cross-Domain Tracking
Verify implementation with these steps:
- Open your browser's developer console
- Visit domain-a.com and check for Kissmetrics cookie
- Identify with a test email:
_kmq.push(['identify', 'test@example.com']); - Visit domain-b.com and identify with the same email
- Check Kissmetrics dashboard for activity under the same person
Best Practices
- Use Consistent Identifiers: Always use the same type of identifier (email, user ID) across all domains
- Identify Early: Call
identify()as soon as you know who the user is - Clear on Logout: Always call
clearIdentity()when users log out - Test Thoroughly: Verify cross-domain tracking in a staging environment before production
- Document Your Strategy: Keep a record of which identifiers you use and when they're set
- Monitor Data Quality: Regularly check your Kissmetrics data for unexpected anonymous users or duplicate identities