appendIdentityToUrl

The appendIdentityToUrl command allows you to add a user identifier to the URL as a query string. This action allows you to carry a visitor’s identity between domains, preventing duplicate visitor counts for datasets that include both domains or channels. It is available on Web SDK versions 2.11.0 or later.

The query string generated and appended to the URL is adobe_mc. If the Web SDK cannot find an ECID, it calls the /acquire endpoint to generate one.

NOTE
If consent has not been provided, the URL from this method is returned unchanged. This command runs immediately; it does not wait for a consent update.

Append identity to URL using the Web SDK extension extension

Appending an identity to a URL is performed as an action within a rule in the Adobe Experience Platform Data Collection tags interface.

  1. Log in to experience.adobe.com using your Adobe ID credentials.
  2. Navigate to Data Collection > Tags.
  3. Select the desired tag property.
  4. Navigate to Rules, then select the desired rule.
  5. Under Actions, select an existing action or create an action.
  6. Set the Extension dropdown field to Adobe Experience Platform Web SDK, and set the Action Type to Redirect with identity.
  7. Click Keep Changes, then run your publishing workflow.

This command is typically used with a specific rule that listens for clicks and checks desired domains.

Rule event criteria

Triggers when an anchor tag with an href property is clicked.

  • Extension: Core
  • Event type: Click
  • When the user clicks on: Specific elements
  • Elements matching the CSS selector: a[href]

Rule event

Rule condition

Triggers only on desired domains.

  • Logic type: Regular
  • Extension: Core
  • Condition Type: Value Comparison
  • Left Operand: %this.hostname%
  • Operator: Matches Regex
  • Right Operand: A regular expression that matches the desired domains. For example, adobe.com$|behance.com$

Rule condition

Rule action

Append the identity to the URL.

  • Extension: Adobe Experience Platform Web SDK
  • Action Type: Redirect with identity

Rule action

Append identity to URL using the Web SDK JavaScript library

Run the appendIdentityToUrl command with a URL as a parameter. The method returns a URL with the identifier appended as a query string.

alloy("appendIdentityToUrl",document.location);

You can add an event listener for all clicks received on the page and check to see if the URL matches any desired domains. If it does, append the identity to the URL and redirect the user.

document.addEventListener("click", event => {
  // Check if the click was a link
  const anchor = event.target.closest("a");
  if (!anchor || !anchor.href) return;

  // Check if the link points to the desired domain
  const url = new URL(anchor.href);
  if (!url.hostname.endsWith(".adobe.com") && !url.hostname.endsWith(".behance.com")) return;

  // Append the identity to the URL, then direct the user to the URL
  event.preventDefault();
  alloy("appendIdentityToUrl", {url: anchor.href}).then(result => {document.location = result.url;});
});

Response object

If you decide to handle responses with this command, the response object contains url, the new URL with identity information added as a query string parameter.

recommendation-more-help
ad108910-6329-42f1-aa1d-5920a2b13636