Développer ma barre des réalisations de la Communauté.

Submissions are now open for the 2026 Adobe Experience Maker Awards

Mark Solution

Cette conversation a été verrouillée en raison de son inactivité. Veuillez créer une nouvelle publication.

RÉSOLU

Want to capture only url after # in page url

Avatar

Level 3

I want to capture url after #tag in page url, how should i set it up in data elements in tag manager.

 

www.link.com#article1

www.link.com#article2

 

So i have created variable Article and i want to store variable article1, article2.. so on.

1 solution acceptée

Avatar

Réponse correcte par
Community Advisor and Adobe Champion

I don't think there's a default standard data element for this, but you can get it using a Custom Code data element using window.location.hash

 

return window.location.hash

 

OR if you need to sanitize the data, or check for values before returning the final value (since often links from FB or other external source could add hash values to your URLs that may not be your "article" values, or if there are any named anchors used in your site like accessible "skip links", or "back to top", etc links that all use #):

 

var hash = window.location.hash;

// Do sanitation and checks here

return hash;

 

Voir la solution dans l'envoi d'origine

1 Reply

Avatar

Réponse correcte par
Community Advisor and Adobe Champion

I don't think there's a default standard data element for this, but you can get it using a Custom Code data element using window.location.hash

 

return window.location.hash

 

OR if you need to sanitize the data, or check for values before returning the final value (since often links from FB or other external source could add hash values to your URLs that may not be your "article" values, or if there are any named anchors used in your site like accessible "skip links", or "back to top", etc links that all use #):

 

var hash = window.location.hash;

// Do sanitation and checks here

return hash;