{"_id":"5a4ad68bf4ab500012e7a98d","project":"560c93ad7e9b9d0d00ca81a2","version":{"_id":"560c93ae7e9b9d0d00ca81a5","project":"560c93ad7e9b9d0d00ca81a2","__v":9,"createdAt":"2015-10-01T02:00:14.709Z","releaseDate":"2015-10-01T02:00:14.709Z","categories":["560c93af7e9b9d0d00ca81a6","560c9d9399bb5a0d0044f220","560d76d899bb5a0d0044f307","560d76ee1ec45619006069ed","560d86e099bb5a0d0044f32e","560dba80373c0e0d0024ff3b","57c722ecdf19130e001fba5d","57c743d1b6f94a2200659903","58995ec083f743190077bbe2"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"category":{"_id":"560c93af7e9b9d0d00ca81a6","version":"560c93ae7e9b9d0d00ca81a5","__v":1,"pages":["560c93b07e9b9d0d00ca81a8"],"project":"560c93ad7e9b9d0d00ca81a2","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-10-01T02:00:15.249Z","from_sync":false,"order":0,"slug":"documentation","title":"Documentation"},"user":"560c92f2ac2859170013faa3","githubsync":"","__v":0,"parentDoc":null,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2018-01-02T00:47:07.162Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":3,"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 **anonymous_id** parameter to links which point to your cross-domain list. It also sets **anonymous_id** if the one is present in current URL. The code below uses jQuery and 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:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"\",\n  \"body\": \"This script is just en example of idea how to implement basic cross-domain tracking. It might not work for you or require some changes.\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"// Attribution snippet code\\nwindow.Attribution=window.Attribution||[];window.Attribution.methods=[\\\"trackSubmit\\\",\\\"trackClick\\\",\\\"trackLink\\\",\\\"trackForm\\\",\\\"pageview\\\",\\\"identify\\\",\\\"group\\\",\\\"track\\\",\\\"ready\\\",\\\"alias\\\",\\\"page\\\",\\\"once\\\",\\\"off\\\",\\\"on\\\"];window.Attribution.factory=function(e){return function(){var t=Array.prototype.slice.call(arguments);t.unshift(e);window.Attribution.push(t);return window.Attribution}};for(var i=0;i<window.Attribution.methods.length;i++){var key=window.Attribution.methods[i];window.Attribution[key]=window.Attribution.factory(key)}window.Attribution.load=function(e){if(document.getElementById(\\\"attribution-js\\\"))return;var t=document.createElement(\\\"script\\\");t.type=\\\"text/javascript\\\";t.id=\\\"attribution-js\\\";t.async=true;t.src=\\\"//scripts.attributionapp.com/attribution.js\\\";var n=document.getElementsByTagName(\\\"script\\\")[0];n.parentNode.insertBefore(t,n)};window.Attribution.load();\\n\\n// set your project key\\nwindow.Attribution.projectId=\\\"YOUR_APP_KEY\\\";\\n\\n// cross-domain hook\\nAttribution.ready(function() {\\n  // list of your hostnames that you want to share visitors\\n  var crossDomains = ['hostA.com', 'www.exampleB.net', 'otherC.com'];\\n\\n  // search current url for anonymous_id\\n  var currentUrl = new URL(window.location.href);\\n  var anonymousId = currentUrl.searchParams.get('anonymous_id');\\n\\n  if (anonymousId) {\\n    // set anonymous id\\n    Attribution.user().anonymousId(anonymousId);\\n  } else {\\n    // read generated anonymous id\\n    anonymousId = Attribution.user().anonymousId();\\n  }\\n\\n  // track current pageview\\n  Attribution.page();\\n\\n  // check every link and tag external links to our crossDomains with anonymous_id\\n  $('a').each(function() {\\n    var link = $(this).attr('href');\\n    // we use try here because not every link is a valid url\\n    try {\\n      var 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        var newLink = link + ((link.indexOf('?') > -1) ? '&' : '?') + 'anonymous_id=' + anonymousId;\\n        // update link to include anonymous_id\\n        $(this).attr('href', newLink);\\n      } else {\\n        // console.warn(link + ' domain is not in our list')\\n      }\\n    }\\n    catch (e) {\\n      // console.warn(link + ' is not an URL');\\n    }\\n  });\\n});\",\n      \"language\": \"javascript\"\n    },\n    {\n      \"code\": \"<script type=\\\"text/javascript\\\">\\n  // Attribution snippet code\\n  window.Attribution=window.Attribution||[];window.Attribution.methods=[\\\"trackSubmit\\\",\\\"trackClick\\\",\\\"trackLink\\\",\\\"trackForm\\\",\\\"pageview\\\",\\\"identify\\\",\\\"group\\\",\\\"track\\\",\\\"ready\\\",\\\"alias\\\",\\\"page\\\",\\\"once\\\",\\\"off\\\",\\\"on\\\"];window.Attribution.factory=function(e){return function(){var t=Array.prototype.slice.call(arguments);t.unshift(e);window.Attribution.push(t);return window.Attribution}};for(var i=0;i<window.Attribution.methods.length;i++){var key=window.Attribution.methods[i];window.Attribution[key]=window.Attribution.factory(key)}window.Attribution.load=function(e){if(document.getElementById(\\\"attribution-js\\\"))return;var t=document.createElement(\\\"script\\\");t.type=\\\"text/javascript\\\";t.id=\\\"attribution-js\\\";t.async=true;t.src=\\\"//scripts.attributionapp.com/attribution.js\\\";var n=document.getElementsByTagName(\\\"script\\\")[0];n.parentNode.insertBefore(t,n)};window.Attribution.load();\\n\\n  // set your project key\\n  window.Attribution.projectId=\\\"YOUR_APP_KEY\\\";\\n\\n  // cross-domain hook\\n  Attribution.ready(function() {\\n    // list of your hostnames that you want to share visitors\\n    var crossDomains = ['hostA.com', 'www.exampleB.net', 'otherC.com'];\\n\\n    // search current url for anonymous_id\\n    var currentUrl = new URL(window.location.href);\\n    var anonymousId = currentUrl.searchParams.get('anonymous_id');\\n\\n    if (anonymousId) {\\n      // set anonymous id\\n      Attribution.user().anonymousId(anonymousId);\\n    } else {\\n      // read generated anonymous id\\n      anonymousId = Attribution.user().anonymousId();\\n    }\\n\\n    // track current pageview\\n    Attribution.page();\\n\\n    // check every link and tag external links to our crossDomains with anonymous_id\\n    $('a').each(function() {\\n      var link = $(this).attr('href');\\n      // we use try here because not every link is a valid url\\n      try {\\n        var 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          var newLink = link + ((link.indexOf('?') > -1) ? '&' : '?') + 'anonymous_id=' + anonymousId;\\n          // update link to include anonymous_id\\n          $(this).attr('href', newLink);\\n        } else {\\n          // console.warn(link + ' domain is not in our list')\\n        }\\n      }\\n      catch (e) {\\n        // console.warn(link + ' is not an URL');\\n      }\\n    });\\n  });\\n</script>\",\n      \"language\": \"html\"\n    }\n  ]\n}\n[/block]","excerpt":"Track your visitors across multiple domains as they are visiting one site.","slug":"cross-domain-tracking","type":"basic","title":"Cross-domain Tracking"}

Cross-domain Tracking

Track your visitors across multiple domains as they are visiting one site.

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 **anonymous_id** parameter to links which point to your cross-domain list. It also sets **anonymous_id** if the one is present in current URL. The code below uses jQuery and 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:callout] { "type": "warning", "title": "", "body": "This script is just en example of idea how to implement basic cross-domain tracking. It might not work for you or require some changes." } [/block] [block:code] { "codes": [ { "code": "// Attribution snippet code\nwindow.Attribution=window.Attribution||[];window.Attribution.methods=[\"trackSubmit\",\"trackClick\",\"trackLink\",\"trackForm\",\"pageview\",\"identify\",\"group\",\"track\",\"ready\",\"alias\",\"page\",\"once\",\"off\",\"on\"];window.Attribution.factory=function(e){return function(){var t=Array.prototype.slice.call(arguments);t.unshift(e);window.Attribution.push(t);return window.Attribution}};for(var i=0;i<window.Attribution.methods.length;i++){var key=window.Attribution.methods[i];window.Attribution[key]=window.Attribution.factory(key)}window.Attribution.load=function(e){if(document.getElementById(\"attribution-js\"))return;var t=document.createElement(\"script\");t.type=\"text/javascript\";t.id=\"attribution-js\";t.async=true;t.src=\"//scripts.attributionapp.com/attribution.js\";var n=document.getElementsByTagName(\"script\")[0];n.parentNode.insertBefore(t,n)};window.Attribution.load();\n\n// set your project key\nwindow.Attribution.projectId=\"YOUR_APP_KEY\";\n\n// cross-domain hook\nAttribution.ready(function() {\n // list of your hostnames that you want to share visitors\n var crossDomains = ['hostA.com', 'www.exampleB.net', 'otherC.com'];\n\n // search current url for anonymous_id\n var currentUrl = new URL(window.location.href);\n var anonymousId = currentUrl.searchParams.get('anonymous_id');\n\n if (anonymousId) {\n // set anonymous id\n Attribution.user().anonymousId(anonymousId);\n } else {\n // read generated anonymous id\n anonymousId = Attribution.user().anonymousId();\n }\n\n // track current pageview\n Attribution.page();\n\n // check every link and tag external links to our crossDomains with anonymous_id\n $('a').each(function() {\n var link = $(this).attr('href');\n // we use try here because not every link is a valid url\n try {\n var 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 var newLink = link + ((link.indexOf('?') > -1) ? '&' : '?') + 'anonymous_id=' + anonymousId;\n // update link to include anonymous_id\n $(this).attr('href', newLink);\n } else {\n // console.warn(link + ' domain is not in our list')\n }\n }\n catch (e) {\n // console.warn(link + ' is not an URL');\n }\n });\n});", "language": "javascript" }, { "code": "<script type=\"text/javascript\">\n // Attribution snippet code\n window.Attribution=window.Attribution||[];window.Attribution.methods=[\"trackSubmit\",\"trackClick\",\"trackLink\",\"trackForm\",\"pageview\",\"identify\",\"group\",\"track\",\"ready\",\"alias\",\"page\",\"once\",\"off\",\"on\"];window.Attribution.factory=function(e){return function(){var t=Array.prototype.slice.call(arguments);t.unshift(e);window.Attribution.push(t);return window.Attribution}};for(var i=0;i<window.Attribution.methods.length;i++){var key=window.Attribution.methods[i];window.Attribution[key]=window.Attribution.factory(key)}window.Attribution.load=function(e){if(document.getElementById(\"attribution-js\"))return;var t=document.createElement(\"script\");t.type=\"text/javascript\";t.id=\"attribution-js\";t.async=true;t.src=\"//scripts.attributionapp.com/attribution.js\";var n=document.getElementsByTagName(\"script\")[0];n.parentNode.insertBefore(t,n)};window.Attribution.load();\n\n // set your project key\n window.Attribution.projectId=\"YOUR_APP_KEY\";\n\n // cross-domain hook\n Attribution.ready(function() {\n // list of your hostnames that you want to share visitors\n var crossDomains = ['hostA.com', 'www.exampleB.net', 'otherC.com'];\n\n // search current url for anonymous_id\n var currentUrl = new URL(window.location.href);\n var anonymousId = currentUrl.searchParams.get('anonymous_id');\n\n if (anonymousId) {\n // set anonymous id\n Attribution.user().anonymousId(anonymousId);\n } else {\n // read generated anonymous id\n anonymousId = Attribution.user().anonymousId();\n }\n\n // track current pageview\n Attribution.page();\n\n // check every link and tag external links to our crossDomains with anonymous_id\n $('a').each(function() {\n var link = $(this).attr('href');\n // we use try here because not every link is a valid url\n try {\n var 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 var newLink = link + ((link.indexOf('?') > -1) ? '&' : '?') + 'anonymous_id=' + anonymousId;\n // update link to include anonymous_id\n $(this).attr('href', newLink);\n } else {\n // console.warn(link + ' domain is not in our list')\n }\n }\n catch (e) {\n // console.warn(link + ' is not an URL');\n }\n });\n });\n</script>", "language": "html" } ] } [/block]