页面加载后,将项目添加到同一Datalayer对象
在我的网站上,我有一个页面对象,其中包含有关该页面的多个信息,这些信息当前正在查看,这些信息我想将其推向Datalayer。 (标题,描述,页面类型等)。
这些信息中的大部分都可以在页面加载中获得,但是只有在AJAX请求之后才有一条信息。 当该对象多次在页面上可用并让GTM识别它是同一对象并在内部组合时,是否可以将此对象作为不完整对象将其推向数据层?
我想做这样的事情:
<!-- within <head> (available on page load)-->
dataLayer.push({
"page":{
"title": "my_page_title",
"description": "my_page_description"
});
(Page completes rendering)
<!-- part of AJAX success response -->
dataLayer.push({
"page":{
"purchasable": true
});
并让GTM解释它与我要做的一样:
dataLayer.push({
"page":{
"title": "my_page_title",
"description": "my_page_description",
"purchasable": true
});
当前,我将完整的页面对象推向AJAX响应后,将完整的页面对象推向数据层,但是我有一个请求尝试移动所有内容到页面加载。移至页面负载更加复杂,因此我试图看看这是否可以作为替代解决方案。
在GTM中,我们有适当的标签将此页面对象映射到自定义尺寸。我不属于执行此配置的团队的一员,因此我没有太多有关该部分的信息。
On my site, I have a page object that contains multiple bits of information about the page that is currently being viewed that I want to push to the datalayer. (Title, description, page type, etc).
Most of this information is available on page load however there is a piece of information that is only available after an ajax request.
Is it possible to push this object to the datalayer as an incomplete object when it is available on the page multiple times and have GTM recognize that it is the same object and combine it internally?
I want to do something like this:
<!-- within <head> (available on page load)-->
dataLayer.push({
"page":{
"title": "my_page_title",
"description": "my_page_description"
});
(Page completes rendering)
<!-- part of AJAX success response -->
dataLayer.push({
"page":{
"purchasable": true
});
and have GTM interpret it the same as if I were to do:
dataLayer.push({
"page":{
"title": "my_page_title",
"description": "my_page_description",
"purchasable": true
});
Currently, I am pushing the complete page object to the datalayer after the ajax response but there is a request to me to try and move everything to the page load. Moving to page load is more complicated so I'm trying to see if this would be possible as an alternative solution.
Within GTM, we have tags in place to map this page object to a custom dimension. I'm not part of the team that does this configuration though so I don't have much information regarding that part.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您创建“ 2” DATALAYER变量时,GTM会在其内部数据模型中自动合并对象。
因此,您可以创建一个访问密钥
page
的数据层变量。在您的代码中,您可以在所有页面数据可用时发出自定义事件:当您在自定义事件上触发标签
page_info
,引用datalayer varibledlv -page
,它将可以访问组合的对象。您可以使用GTM调试模式对此进行测试。
The GTM merges objects automatically in its internal data model, when you create a "Version 2" DataLayer Variable.
Hence, you could create a DataLayer variable that accesses the key
page
. In your code you can emit a custom event when all the page data is available:When you trigger a tag on your custom event
page_info
that references the dataLayer variableDLV - page
, it will have access to the combined object.You can use the GTM debug mode to test this.