Expand my Community achievements bar.

Join us January 15th for an AMA with Champion Achaia Walton, who will be talking about her article on Event-Based Reporting and Measuring Content Groups!
SOLVED

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 Accepted Solution

Avatar

Correct answer by
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;

 

View solution in original post

1 Reply

Avatar

Correct answer by
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;