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.
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.
Appending an identity to a URL is performed as an action within a rule in the Adobe Experience Platform Data Collection tags interface.
This command is typically used with a specific rule that listens for clicks and checks desired domains.
Triggers when an anchor tag with an href
property is clicked.
a[href]
Triggers only on desired domains.
%this.hostname%
adobe.com$|behance.com$
Append the identity to the URL.
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;});
});
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.