{"metadata":{"image":[],"title":"","description":""},"api":{"url":"","auth":"required","settings":"","results":{"codes":[]},"params":[]},"next":{"description":"","pages":[]},"title":"Cross-domain tracking","type":"basic","slug":"cross-domain-tracking-1","excerpt":"How to track multiple domains against one project","body":"If you have multiple different domains you want to track as a single site then this hook will work for you. It works by adding **anonymousId** parameter to all links which point to your cross-domain list. It also sets **ajs_aid** if the one is present in current URL. The code below should work for most setups, please update **crossDomains** variable to include all of your sites' domains (hostnames) you want to track. This code need to be placed on every site.\n[block:api-header]\n{\n  \"title\": \"Example script\"\n}\n[/block]\nThe script below is an example of what a cross-domain script may look like. You should be aware to adjust crossDomains for tracking. Also it only tracks HTML links, if you have JavaScript navigation or redirects this script might not be sufficient.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"// Add Attribution App snippet code first\\n// https://dashboard.attributionapp.com/goto/settings/instructions\\n\\nAttribution.ready(function() {\\n  // list of your hostnames that you want to share visitors\\n  const crossDomains = ['hostA.com', 'www.exampleB.net', 'otherC.com'];\\n\\n  const currentUrl = new URL(window.location.href);\\n\\n  // check every link and tag external links to our crossDomains with ajs_aid\\n  const links = document.body.getElementsByTagName('a');\\n  for (var i = 0; i < links.length; i++) {\\n    let link = links[i].getAttribute('href');\\n    if (link == null) {\\n      continue;\\n    } else if (link.startsWith('//')) {\\n      // inherit current protocol\\n      link = currentUrl.protocol + link;\\n    } else if (link.startsWith('/')) {\\n      continue; // local link\\n    }\\n\\n    // we use try here because not every link is a valid url\\n    try {\\n      const url = new URL(link);\\n\\n      // if not current hostname and hostname is in our cross-domain list\\n      if ((url.hostname !== currentUrl.hostname) && (crossDomains.indexOf(url.hostname) > -1)) {\\n        const newLink = link + ((link.indexOf('?') > -1) ? '&' : '?') + 'ajs_aid=' + Attribution.user().anonymousId();\\n        // update links to contain anonymous_id in 'ajs_aid' param\\n        links[i].setAttribute('href', newLink);\\n      }\\n    }\\n    catch (e) {\\n      // for debugging\\n      // console.warn(link + ' is not an URL');\\n    }\\n  }\\n});\\n\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nOnce you've adjusted the snippet above you can install it on all your pages to begin tracking cross-domain as one project. You should use this in a case where you may have domainA & domainB, but you want to see return on ad spend for both in one project. \n\nIf you have any questions please reach out to help:::at:::attributionapp.com","updates":[],"order":0,"isReference":false,"hidden":false,"sync_unique":"","link_url":"","link_external":false,"_id":"600060e3f3d8e9003caf7297","createdAt":"2021-01-14T15:18:59.735Z","user":"560c92f2ac2859170013faa3","category":{"sync":{"isSync":false,"url":""},"pages":[],"title":"FAQ when installing","slug":"faq-when-installing","order":2,"from_sync":false,"reference":false,"_id":"600060c72dcd9d002fa13656","createdAt":"2021-01-14T15:18:31.879Z","version":"560c93ae7e9b9d0d00ca81a5","project":"560c93ad7e9b9d0d00ca81a2","__v":0},"version":{"version":"1.0","version_clean":"1.0.0","codename":"","is_stable":true,"is_beta":false,"is_hidden":false,"is_deprecated":false,"categories":["560c93af7e9b9d0d00ca81a6","560c9d9399bb5a0d0044f220","560d76d899bb5a0d0044f307","560d76ee1ec45619006069ed","560d86e099bb5a0d0044f32e","560dba80373c0e0d0024ff3b","57c722ecdf19130e001fba5d","57c743d1b6f94a2200659903","58995ec083f743190077bbe2","5fabfb070e9b0600424707dd","60004359deee820012dc1efc","600060c72dcd9d002fa13656","6001ac08c104fe002b933b7c","6009604d81b288001417df30","60097b7be8ec1e00334419f6","600aa98de28fae003a33108a","600aa9ee7d3e350018e7d6e4","601176819ca8c90011cfe6ac","606eef795bb7ed00790e9e68","609bf103a1334800624b7541"],"_id":"560c93ae7e9b9d0d00ca81a5","project":"560c93ad7e9b9d0d00ca81a2","createdAt":"2015-10-01T02:00:14.709Z","releaseDate":"2015-10-01T02:00:14.709Z","__v":20},"project":"560c93ad7e9b9d0d00ca81a2","__v":0,"parentDoc":null}

Cross-domain tracking

How to track multiple domains against one project

If you have multiple different domains you want to track as a single site then this hook will work for you. It works by adding **anonymousId** parameter to all links which point to your cross-domain list. It also sets **ajs_aid** if the one is present in current URL. The code below should work for most setups, please update **crossDomains** variable to include all of your sites' domains (hostnames) you want to track. This code need to be placed on every site. [block:api-header] { "title": "Example script" } [/block] The script below is an example of what a cross-domain script may look like. You should be aware to adjust crossDomains for tracking. Also it only tracks HTML links, if you have JavaScript navigation or redirects this script might not be sufficient. [block:code] { "codes": [ { "code": "// Add Attribution App snippet code first\n// https://dashboard.attributionapp.com/goto/settings/instructions\n\nAttribution.ready(function() {\n // list of your hostnames that you want to share visitors\n const crossDomains = ['hostA.com', 'www.exampleB.net', 'otherC.com'];\n\n const currentUrl = new URL(window.location.href);\n\n // check every link and tag external links to our crossDomains with ajs_aid\n const links = document.body.getElementsByTagName('a');\n for (var i = 0; i < links.length; i++) {\n let link = links[i].getAttribute('href');\n if (link == null) {\n continue;\n } else if (link.startsWith('//')) {\n // inherit current protocol\n link = currentUrl.protocol + link;\n } else if (link.startsWith('/')) {\n continue; // local link\n }\n\n // we use try here because not every link is a valid url\n try {\n const url = new URL(link);\n\n // if not current hostname and hostname is in our cross-domain list\n if ((url.hostname !== currentUrl.hostname) && (crossDomains.indexOf(url.hostname) > -1)) {\n const newLink = link + ((link.indexOf('?') > -1) ? '&' : '?') + 'ajs_aid=' + Attribution.user().anonymousId();\n // update links to contain anonymous_id in 'ajs_aid' param\n links[i].setAttribute('href', newLink);\n }\n }\n catch (e) {\n // for debugging\n // console.warn(link + ' is not an URL');\n }\n }\n});\n", "language": "javascript" } ] } [/block] Once you've adjusted the snippet above you can install it on all your pages to begin tracking cross-domain as one project. You should use this in a case where you may have domainA & domainB, but you want to see return on ad spend for both in one project. If you have any questions please reach out to [email protected]