简体   繁体   English

从dataLayer总计中删除$-Google跟踪代码管理器

[英]remove $ from dataLayer total - google tag manager

I have this datalayer on my completion checkout page. 我的结帐页面上有这个数据层。 everything is working it fires fine. 一切正常,一切正常。 All is well for Adwords. Adwords一切都很好。 however another ad words tracking script isn't passing the value back to the website. 但是,另一个广告词跟踪脚本并未将价值传递回网站。 I believe it's because the $ sign. 我相信是因为$符号。 how can i trim the dollar sign off of the summary.total_formatted? 我如何从summary.total_formatted中删减美元符号?

<script>
dataLayer.push({'subtotal':'<%= summary.total_formatted %>'});
</script>

I was thinking something like this here, 我在这里想像这样的事情

dataLayer.push({'subtotal':'<%= summary.total_formatted %>'[0].innerHTML.trim().replace('$','')});

but this is wrong gives me an arrow with the trim actually. 但这是错误的,实际上给了我一个带有修饰的箭头。 what is the best way to handle this so the price is pasted back to the 3rd party website. 解决此问题的最佳方法是什么,以便将价格粘贴回第三方网站。 I just want to exclude the $ sign to test this. 我只想排除$符号进行测试。

You can replace it directly var subTotal = '<%= summary.total_formatted %>'; 您可以直接将其替换var subTotal ='<%= summary.total_formatted%>'; var dataLayer = []; var dataLayer = []; dataLayer.push({'subtotal' : subTotal .replace('$','')}); dataLayer.push({'subtotal':subTotal .replace('$','')});;

console.log(JSON.stringify(dataLayer));

Here is a jsfiddle 这是一个jsfiddle

Hope this helps. 希望这可以帮助。

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

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