We moved from GTM to DTM a little over 6 weeks ago and I'm still getting to grips with its functions.
I need to capture the page name in a Data Element using a DTM script/property used over two different domains.
Domain 1 has a dataLayer, where I can use the standard 'JS Object' option to retrieve the page name e.g. digitalData.page.name
Domain 2 does not have a dataLayer and I have to use the CSS selector for where a business page name has been defined (not document.title) to retrieve the page name e.g. Data Element option is CSS Selector, #WebMIPageName and return 'other' value of 'content'
What I would like to know if there a way to write a piece of code using the code editor option in Data Elelment to look for both and return the page name?
IF digitalData.page.name OR #WebMIPageName then return value or 'content'
As you can tell I have no code/java experience so I hope this makes sense..
This solution uses an undocumented feature of DTM's _satellite.getVar where you can directly access window scoped objects. What's nice is that it will fail gracefully if any part of the referenced object does not exist. This feature has not been moved forward into Launch, so you would have an issue if you wanted to bring these data elements from DTM into Launch at some point.
Many thanks for your help. Due to a regulatory requirement the site has to go live by a set date, with or without a dataLayer, but I will have one roughly 2-3 weeks later.
Option two was a no brainer as I already created two of the data elements in your suggestion. I had one with an event to record the CSS selector page name as an eVar which I was then using in "Process Rules" in the report suite to populate the page name where it wasn't set. Works, but not very slick.