Cross-domain Conversation Continuity

Implement cross-domain conversation continuity in the era of first-party cookies.

Discover how iAdvize handles data storage in this Help Center article : https://help.iadvize.com/hc/articles/216438047

Since the 2024 phase-out of third-party cookies, iAdvize can no longer reliably link visitor identities across domains. While this is good news for privacy in general, it means that multi-domain clients need to add a query parameter to their pages to maintain conversation continuity between websites that do not share a top-level domain.

This is how it should be implemented :

  1. Use the iAdvize WebSDK to retrieve the conversationId when a conversation is ongoing :

window.iAdvizeInteface.push((iAdvize) => {
  iAdvize.on("conversation:idChange", (conversationId) => {
    // This is triggered when : 
    // - a conversation starts : conversationId is a string
    // - a conversation ends : conversationId is null
  });
});
  1. Add the conversationId to all relevant links.

Here is a full example of what it might look like :

<script>
  /**
   * Script setup
   * You should use your own values
   **/
  window.iAdvizeInterface = window.iAdvizeInterface || [];
  iAdvizeInterface.config = {
      "sid": 1234,
      "lang": "en",
      "useExplicitCookiesConsent": true
  };

  /**
   * Function to update all the links on the website's page.
   * We need them to include the conversation identifier, 
   * so cross-domain conversations can be continued.
   **/
  function updateLinksWithConversationId(conversationId) {
    // List of allowed top level domains, on which we want conversation continuity
    const TOP_LEVEL_DOMAINS = ["my-first-domain.com", "my-other-domain.net"];
    // The query param key we will add to relevant links
    const queryParam = "idzconvid";

    const links = document.body.querySelectorAll("a");
    for (const link of links) {
      const originalUrl = new URL(link.href);
      const isRelevantLink = TOP_LEVEL_DOMAINS.some((domain) =>
        originalUrl.hostname.includes(domain)
      );
      if (!isRelevantLink) continue;
      originalUrl.searchParams.delete(queryParam);
      if (conversationId) {
        originalUrl.searchParams.append(queryParam, conversationId);
      }
      link.href = originalUrl.href;
    }
  }

  // When iAdvize is loaded :
  window.iAdvizeInterface.push((iAdvize) => {
    // Change relevant links if a conversation is already ongoing
    updateLinksWithConversationId(iAdvize.get("conversation:id"));
    // Listen to conversationId changes to update relevant links
    iAdvize.on("conversation:idChange", updateLinksWithConversationId);
  });
</script>

<!-- Launch the iAdvize tag -->
<script async src="//halc.iadvize.com/iadvize.js"></script>

See an example in this codesandbox : https://codesandbox.io/p/sandbox/cross-domain-conversation-continuity-hyx6fx

Last updated