在另一个GTM JavaScript变量中返回GTM JavaScript变量(数组)的总和(Return total of a GTM JavaScript variable (array) in another GTM JavaScript variable)
这是我在这个网站上的第一个问题,我很好奇是否有人可以帮助我。 在Google跟踪代码管理器中,我尝试使用一些jQuery设置自定义JavaScript变量,该变量应返回特定数组中的所有产品价格的总量。
在下面的代码中,我返回增强型电子商务数据图层中的所有产品价格。 在GTM中,我将此变量称为“{{product price}}”。
function() { var itemsInC = {{ecommerce.checkout.products}}; itemsincart = []; for (var i = 0;i < itemsInC.length;i++) { priceincart.push(itemsInC[i].price); } return priceincart; }
上面的代码实际工作,例如返回一个值,如:['9.99','21 .95','34 .99']。
在第二段代码中,我尝试总结GTM变量“{{product price}}”中所有返回值的总和。 但是,下面的代码无法正常工作。 我怎样才能在下面的脚本中返回上面脚本的总值?
这是我迄今创建的:
function() { var total = $("{{product price}}").each(function() { 0 += parseInt($(this).val(), 10); } return total; }
提前致谢!
亲切的问候,
This is my very first question on this website, I am curious if someone could help me out. In Google Tag Manager I tried to set up a custom JavaScript variable with some jQuery that should return the total amount of all product prices within a specific array.
In the code below I return all product prices within an Enhanced Ecommerce dataLayer. In GTM, I have called this variable "{{product price}}".
function() { var itemsInC = {{ecommerce.checkout.products}}; itemsincart = []; for (var i = 0;i < itemsInC.length;i++) { priceincart.push(itemsInC[i].price); } return priceincart; }
The code above actually works and for example returns a value like: ['9.99', '21.95', '34.99'].
In the second piece of code I try to sum up the total of all returned values in the GTM variable "{{product price}}". However, the code below doesn't work properly. How could I return the total value of the script above in the script below?
This is what I created so far:
function() { var total = $("{{product price}}").each(function() { 0 += parseInt($(this).val(), 10); } return total; }
Thanks in advance!
Kind regards,
原文:https://stackoverflow.com/questions/34398263
最满意答案
这是因为Heroku在严格模式之外使用的Node版本中尚不支持块范围声明(
let
,const
)。所以有两个选择:
- 添加
"use strict";
在您的文件的开头- 使用
var
而不是let
。That is because Block-scoped declarations (
let
,const
) are not yet supported in the Node version Heroku is using outside of strict mode.So two options:
- Add
"use strict";
at the beginning of your file- Use
var
and notlet
.
相关问答
更多-
如文档中所述,您也可以使用非GitHub远程 (如Heroku)。 As specified in the documentation, you can use a non-GitHub remote (like Heroku) also.
-
尝试做到这一点: 编辑Git配置文本文件(用我最喜欢的结束中立应用程序,如Notepad ++)位于: C:\Program Files (x86)\Git\etc\gitconfig 在[http]块中,添加一个选项来禁用sslVerify。 当我完成时,它看起来像这样: [http] sslVerify = false sslCAinfo = /bin/curl-ca-bundle.crt 答案与此有关 The problem was that I have a web filter on my i ...
-
用git clone git@github...像正常一样克隆回购。 然后cd进入目录并运行heroku create [an optional app name] 。 然后,你将有两个Git远程设置,用于回购(起源),一个用于heroku应用程序(heroku)。 然后'git push heroku master'将部署到heroku。 Clone the repo like normal with git clone git@github... . Then cd into the directory ...
-
使用github部署Heroku评论应用程序:如何更改用户部署(Heroku review app deploy with github: how to change the user deploying)[2023-04-29]
我发现这样做的唯一方法是在Heroku中取消链接github功能,并重新链接到我想使用的帐户。 The only way I found to do this was to un-link the github capability in Heroku, and re-link with the account I wanted to use. -
Github直接到了heroku(Github straight to heroku)[2022-08-09]
这听起来是不可能的: 从github推送到heroku而不下载repo Sounds like this isn't possible: Push from github to heroku without downloading repo -
您可能已在Heroku应用程序上启用了GitHub集成。 您仍然拥有一个Heroku应用程序 - 这就是您启用GitHub集成的功能。 如果您的应用程序名称为foo-bar-123则heroku logs -a foo-bar-123应该执行此操作。 You have probably enabled GitHub integration on your Heroku app. You still have a Heroku app right - that's what you enabled the G ...
-
您需要删除以前的遥控器: git remote rm heroku 然后使用新的应用名称添加它: git remote add heroku https://git.heroku.com/
.git 进一步推送将在您的新应用程序而不是旧应用程序上发生。 或者下次,如果您先移除遥控器, heroku create将设置新遥控器以便于推送。 You need to remove the previous remote: git remote rm heroku Then add it w ... -
我能够使用nodejs和expressJs使它工作。 通过跟随heroku“开始使用nodejs”,我能够通过expressjs获得一个有效的webapp并在web.js中声明: var express = require("express"); var app = express(); app.use(express.logger()); app.use("/", express.static(__dirname)); var port = process.env.PORT || 5000; app.l ...
-
无法将Nodejs应用程序部署到Heroku(找不到凉亭)(Unable to deploy a Nodejs application to Heroku (bower not found))[2022-01-30]
请尝试将其替换为postinstall: "postinstall": "./node_modules/bower/bin/bower install" 这是因为bower本地安装在指定的路径中,而不是全局安装。 Try this instead for the postinstall: "postinstall": "./node_modules/bower/bin/bower install" This is because bower is installed locally in the spe ... -
这是因为Heroku在严格模式之外使用的Node版本中尚不支持块范围声明( let , const )。 所以有两个选择: 添加"use strict"; 在您的文件的开头 使用var而不是let 。 That is because Block-scoped declarations (let, const) are not yet supported in the Node version Heroku is using outside of strict mode. So two options: Ad ...