How can I write page level codes when using Adobe Dynamic Tag Manager (DTM)?

北城以北 提交于 2019-12-13 03:43:25

问题


I am migrating from static implementation to Adobe DTM. There are certain page level codes like for example, s.prop14=Name of Article. But now when I have given the reference of DTM, the page level codes are not firing and I am getting the error in console that object "s" is not defined.

What's the solution for this?

Thanks!


回答1:


By default, DTM does not put the s object (or whatever other namespace you specify in the config) in the global (window) scope, and DTM doesn't natively allow you to. You will have to update your tool config to do it yourself, and incidentally, this also means you will have to maintain the core library yourself instead of making use of the "Managed by Adobe" feature, to get around DTM trying to do it automatically.

In the Library Management > Code Configuration section, choose Custom and check the Set report suites using custom code below. Then you will need to either host the library either "In DTM" (click on "Open Editor" and copy/paste it into there) or "At URL" (host the file yourself). At the top (whether in editor or in file), you will need to instantiate the object under the window namespace. Example for AppMeasurement:

window.s = new AppMeasurement();

Alternatively, you can leave your setup as-is, and change the on-page syntax a bit, and then add some code to DTM to look for it. For example, above your on-page custom code, just do

var s = {};
s.prop1 = 'foobar';
//etc..

And then in DTM, in the same code editor (or in a rule.. lots of places within DTM you can do this), you can do for example:

for (var v in window.s) {
  s[v] = window.s[v];
}


来源:https://stackoverflow.com/questions/27062726/how-can-i-write-page-level-codes-when-using-adobe-dynamic-tag-manager-dtm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!