appendVisitorIDsTo (Cross-Domain Tracking) appendvisitoridsto-cross-domain-tracking

This function lets you share a visitor’s Experience Cloud ID across domains when browsers block third-party cookies. To use this function, you must have implemented the ID service and own the source and destination domains. Available in VisitorAPI.js version 1.7.0 or higher.

Contents:

Track Visitors Across Domains When Browsers Block Third-Party Cookies section-7251d88befd440b4b79520e33c5aa44a

ID service writes a first- and third-party cookie to the browser when a person visit your site (see Cookies and the Experience Cloud Identity Service ). The first-party cookie contains the MID, a unique ID for that visitor. The third-party cookie contains another ID used by the ID service to generate the MID. When a browser blocks this third-party cookie, the ID service cannot:

  • Regenerate the unique ID for that site visitor when they navigate to another domain.
  • Track visitors across different domains owned by your organization.

To help solve this problem, implement Visitor.appendVisitorIDsTo( *url*). This property lets the ID service track site visitors across multiple domains even when their browsers block third-party cookies. It works like this:

  • As a visitor browses to your other domains, the Visitor.appendVisitorIDsTo( *url*) appends the MID as a query parameter in the URL redirect from the original domain to the destination domain.
  • The ID service code on the destination domain extracts the MID from the URL instead of sending a request to Adobe for that visitor’s ID. This request includes the third-party cookie ID, which is not available in this case.
  • The ID service code on the destination page uses the passed-in MID to track the visitor.

See the code sample for details.

Append Visitor ID Code Sample section-62d55f7f986542b0b9238e483d50d7b0

The following example code can help you get started with the appendVisitorIDsTo function:

TIP
This code can be placed in the Custom Code editor that’s part of the Adobe Analytics extension or at the top of AppMeasurement.js.
var adbeDomains = ["marketo.com", "figma.com", "workfront.com"];
var visitor = Visitor.getInstance("9E1005A551ED61CA0A490D45@AdobeOrg", {
  trackingServer: "sstats.adobe.com",
  trackingServerSecure: "sstats.adobe.com",
  marketingCloudServer: "sstats.adobe.com",
  marketingCloudServerSecure: "sstats.adobe.com"
});
adbeDomains.forEach(function(domain) {
  var domainRegex = RegExp(domain);
  if (!domainRegex.test(location.hostname)) {
    hrefSelector = '[href*="' + domain + '"]';
    document.querySelectorAll(hrefSelector).forEach(function(href) {
      href.addEventListener('mousedown', function(event) {
        var destinationURLWithVisitorIDs = visitor.appendVisitorIDsTo(event.currentTarget.href)
        event.currentTarget.href = destinationURLWithVisitorIDs.replace(/MCAID%3D.*%7CMCORGID/, 'MCAID%3D%7CMCORGID');
      });
    });
  }
});
recommendation-more-help
9c9e8ca9-9f7e-42c9-a5d5-a0d82776362a