简体   繁体   English

Google Tag Manager - 用于提取 dataLayer 变量的自定义 javascript

[英]Google Tag Manager - custom javascript to extract dataLayer variable

Firstly, apologies for the lack of technical know-how...首先,为缺乏技术知识而道歉......

I have a datalayer variable in google tag manager which I want to extract information from using custom javascript but I'm not the most technical.我在 google 标签管理器中有一个 datalayer 变量,我想从使用自定义 javascript 中提取信息,但我不是最技术的。

From the picture attached, I want to extract the 'Desc' part of each line separated by comma:从附图中,我想提取每行的“Desc”部分,以逗号分隔:

VCD-95K-ZL6-36T-22F, 40% Off Menswear VCD-95K-ZL6-36T-22F,男装折扣40%

How would the custom javascript for this look like so I can enter it in google tag manager?这个自定义 javascript 看起来如何,以便我可以在谷歌标签管理器中输入它?

Thank you谢谢

在此处输入图片说明

Sure, here you go:喏,给你:

 ["Name:code, Desc:whatever desc is, the first desc basically", "Name:auto, Desc:the second description"] .map(function(obj){return obj.split(/, desc:/i).slice(-1)[0]}).join(",")

The first line is just me trying to reproduce what you have in your DLV for testing purposes.第一行只是我试图重现您在 DLV 中的内容以进行测试。 The second line is what you'd have to do to your DLV, so your actual code in your custom jsvascript variable would look similar to this:第二行是您必须对 DLV 执行的操作,因此您的自定义 jsvascript 变量中的实际代码将类似于以下内容:

 function(){ return {{dlv - ecommerce.purchase.actionField.coupon}}.map(function(obj){return obj.split(/, desc:/i).slice(-1)[0]}).join(","); }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM