Cross-Domain Tracking Overview
GoSquared enables visitor tracking across multiple domains and subdomains using user identification. This allows you to maintain a unified view of customer journeys that span different properties such as marketing sites, application domains, and checkout systems.
How Cross-Domain Tracking Works
GoSquared uses user identification rather than cookie-based linking to track users across domains. When you identify a user with a consistent ID on all domains, GoSquared automatically merges their activity into a single user profile.
Key Concepts
- User ID: A unique identifier consistent across all your domains
- Automatic Merging: User profiles automatically consolidate when same ID is used
- Cookie Scope: Each domain maintains its own cookies, but user data unifies server-side
- Anonymous to Identified: Anonymous sessions convert to identified when user logs in
Implementation Approach
Basic User Identification
Implement consistent user identification on all domains:
// On domain1.com
_gs('identify', {
id: 'user_123',
email: 'john@example.com',
name: 'John Doe'
});
// On domain2.com - use the SAME user ID
_gs('identify', {
id: 'user_123',
email: 'john@example.com',
name: 'John Doe'
});
After User Login
Call identify immediately after successful authentication:
// After login success
_gs('identify', {
id: userObject.id,
email: userObject.email,
name: userObject.full_name,
created_at: userObject.created_at
});
With Single Sign-On (SSO)
For SSO implementations, identify users on each domain they access:
// On each domain after SSO authentication
_gs('identify', {
id: ssoUser.globalId,
email: ssoUser.email,
company: ssoUser.organization
});
Subdomain Tracking
Tracking works automatically across subdomains when properly configured.
Automatic Subdomain Tracking
- Install same project token on all subdomains
- Set cookie domain to root domain:
_gs('GSN-123456-A');
_gs('set', 'cookieDomain', '.example.com'); // Note the leading dot
Example Configuration
<!-- On www.example.com -->
<script>
!function(g,s,q,r,d){r=g[r]=g[r]||function(){(r.q=r.q||[]).push(arguments)};
d=s.createElement(q);d.src='//d1l6p2sc9645hc.cloudfront.net/gosquared.js';
q=s.getElementsByTagName(q)[0];q.parentNode.insertBefore(d,q)}
(window,document,'script','_gs');
_gs('GSN-123456-A');
_gs('set', 'cookieDomain', '.example.com');
</script>
<!-- On app.example.com - same configuration -->
<script>
!function(g,s,q,r,d){r=g[r]=g[r]||function(){(r.q=r.q||[]).push(arguments)};
d=s.createElement(q);d.src='//d1l6p2sc9645hc.cloudfront.net/gosquared.js';
q=s.getElementsByTagName(q)[0];q.parentNode.insertBefore(d,q)}
(window,document,'script','_gs');
_gs('GSN-123456-A');
_gs('set', 'cookieDomain', '.example.com');
</script>
Different Domain Tracking
For tracking across completely different domains (e.g., mysite.com and myapp.io):
Step 1: Install Tracking
Install GoSquared with the same project token on all domains:
// On mysite.com and myapp.io
_gs('GSN-123456-A');
Step 2: Implement Consistent Identification
Use identical user IDs on both domains:
// On mysite.com
_gs('identify', {
id: 'user_abc123',
email: 'customer@email.com'
});
// On myapp.io - MUST use same ID
_gs('identify', {
id: 'user_abc123',
email: 'customer@email.com'
});
Step 3: Verify Unification
Check the People section in GoSquared to verify the user profile shows activity from both domains.
Common Use Cases
Marketing Site to Application
Track users from marketing site through to application:
// On marketing.example.com
_gs('GSN-123456-A');
// Track anonymous visitors
// After signup, when redirecting to app.example.com
_gs('identify', {
id: newUser.id,
email: newUser.email,
signed_up_at: new Date().toISOString()
});
// On app.example.com (after redirect)
_gs('GSN-123456-A');
_gs('identify', {
id: currentUser.id,
email: currentUser.email
});
Multi-Brand Tracking
Track users across multiple brand properties:
// Shared user identification function
function identifyUser(user) {
_gs('identify', {
id: user.globalCustomerId,
email: user.email,
brand: window.location.hostname
});
}
// Called on all brand domains
identifyUser(currentUser);
Troubleshooting
| Issue | Possible Cause | Solution |
|---|---|---|
| Duplicate profiles created | Different user IDs used | Ensure consistent ID across domains |
| Subdomain tracking not working | Incorrect cookie domain | Set cookieDomain to .example.com |
| User profile not merging | Identify not called | Call _gs('identify') on both domains |
| Anonymous sessions separate | Late identification | Identify users as early as possible |
| Data not appearing | Different project tokens | Use same token across all domains |
Verification Steps
1. Check Browser Cookies
Inspect cookies on each domain:
// In browser console on each domain
document.cookie.split(';').filter(c => c.includes('_gs'));
2. Verify User Profile
- Visit Domain A and identify yourself
- Visit Domain B and identify with same ID
- Check GoSquared People → find your profile
- Verify activity from both domains appears in timeline
3. Test Anonymous to Identified
- Visit site anonymously
- Sign up or log in
- Verify anonymous session merges with identified profile
Best Practices
- Consistent User IDs: Use the same unique identifier across all properties
- Early Identification: Identify users as soon as authentication occurs
- Include Email: Always include email for better profile matching
- Test Thoroughly: Verify cross-domain tracking in staging environment
- Document Flow: Map out user journey across domains
- Monitor Profiles: Regularly check for duplicate profiles
- Handle Logout: Clear identification when users log out
Code Example: Complete Implementation
<!-- Template for all domains -->
<script>
!function(g,s,q,r,d){r=g[r]=g[r]||function(){(r.q=r.q||[]).push(arguments)};
d=s.createElement(q);d.src='//d1l6p2sc9645hc.cloudfront.net/gosquared.js';
q=s.getElementsByTagName(q)[0];q.parentNode.insertBefore(d,q)}
(window,document,'script','_gs');
// Initialize with same token on all domains
_gs('GSN-123456-A');
// Set cookie domain for subdomains
_gs('set', 'cookieDomain', '.example.com');
// Identify user if authenticated
if (window.currentUser) {
_gs('identify', {
id: window.currentUser.id,
email: window.currentUser.email,
name: window.currentUser.name,
plan: window.currentUser.plan,
domain: window.location.hostname
});
}
</script>