Tracking becomes complicated when your marketing site and your web app live on entirely different domains (e.g., www.myapp.com and app.mysoftware.io).
Browsers intentionally prevent domains from reading each other's cookies for security reasons. If a user clicks an affiliate link and lands on myapp.com, the cookie is set there. When they click "Login" and are redirected to mysoftware.io, the affiliate cookie is left behind.
The Solution: URL Passing
To track across separate domains, you must manually pass the affiliate ID in the URL when the user navigates between them.
Step 1: Read the Cookie on Domain A
When the user clicks a link to go to Domain B, intercept the click, read the dma_aff_ref cookie, and append it to the URL.
// On www.myapp.com
document.getElementById('login-btn').addEventListener('click', function(e) {
e.preventDefault();
// Helper function to get cookie value
const getCookie = (name) => {
const value = `; ${document.cookie}`;
const parts = value.split(`; ${name}=`);
if (parts.length === 2) return parts.pop().split(';').shift();
};
const affiliateId = getCookie('dma_aff_ref');
let redirectUrl = 'https://app.mysoftware.io/signup';
if (affiliateId) {
redirectUrl += `?ref=${affiliateId}`;
}
window.location.href = redirectUrl;
});
Step 2: Catch the Parameter on Domain B
Ensure that Domain B (app.mysoftware.io) also has the track.js script installed!
When the user lands on the signup page with ?ref=... in the URL, the script on Domain B will catch it and set a fresh cookie on the new domain.
[!NOTE] If you are just using subdomains (e.g.,
www.myapp.comandapp.myapp.com), you do not need to do this. Our script automatically sets the cookie on the root domain (.myapp.com), making it accessible across all subdomains natively.