I recently ran into an issue with accessing DTM Data Elements across subdomains — they weren’t available. After a bit of research, I discovered that DTM makes use of Cookies to provide access to Data Elements if you select to remember the value for the Session or the Visitor.
The problem with the DTM Data Element Cookie is that it is set with the Host equal to the absolute domain, which when trying to access the Data Element from a subdomain becomes very problematic.
In my case, I’m trying to capture a campaign tracking code into a Data Element, on www.domain.com, and then access it later in the visit when the visitor purchases on shop.domain.com, however this is not possible using Data Elements “out of the box”.
What to do? I decided that the best approach, for this particular use case, was to simply forgo the Data Element and instead use my own Cookie. To do this, I deployed a block of code, shown below, on all pages of the site, leveraging an existing Page Load rule that fires on all pages.
The following code lives under Rule Conditions–>Custom:
trackingCode = getParameterByName('mc'); if (trackingCode){ host = location.host; domainParts = host.split('.'); domainParts.shift(); domain = '.'+domainParts.join('.'); document.cookie="_dtm_Tracking Code="+trackingCode+"; path=/; expires=Fri, 31 Dec 9999 23:59:59 GMT; domain="+domain; } return true;
Notice that the code grabs the current domain and formats it so that the Cookie will be accessible across subdomains. You can also manipulate the expires parameter to mimic a Session or Visitor based Data Element.
Next, on the purchase page, which lives on shop.domain.com, I want to conditionally fire a rule if the Visitor came to the site from a specific tracking code, which is now possible as my tracking code is stored in a Cookie that is easily accessible across subdomains.
Admittedly, this is a bit of a hack, yet one that fixes the problem. The best long-term solution for this issue would be for Adobe to provide an enhancement that allows for Data Element access across subdomains and perhaps in the short term some caring individual could find an elegant solution to hijack the DTM setCookie function to allow for Cookies to be accessible across subdomains.