Common problems when referencing a data element using custom code in DTM are:
- Using the _satellite.readcookie() method to call a data element.
- Inability to read query string with s.referrer
When calling a data element whose persistence is set to session or visitor, DTM writes the returned value into a cookie.
In that case, the value can be referenced by calling _satellite.readCookie (‘sdsat’ + dataElementName) which gives the returned value without rerunning the custom script in the data element.
Alternatively, the data element can be referenced by calling _satellite.getVar(dataElementName) which returns the value by rerunning the custom script code.
Keep in mind that Data Elements do not exist until they are called. They are called when accessed in the UI, when calling _satellite.track, or by a custom script or a rule.
If you’re only using the value within a certain page, you can access the data element in the page load rule. Then, if you access that value again on the same page, you can access the data element again. In this case, it would only work after running the custom script again.
For passing the data element to the s.referrer method, ensure that there is a custom script that first calls the data element. After the script calls the data element, pass it into the s.referrer method.
As a quick fix, you can create a rule without conditions that fires on every page. Referencing a data element on the relevant page can then ‘create’ it. After it is created, it can be then passed into the s.referrer method using the following code: s.referrer = _satellite.getVar(<data element name>)