使用 AppMeasurement 安装此插件

在实例化(使用 s_gi)Analytics 跟踪对象后,将以下代码复制并粘贴到 AppMeasurement 文件中的任意位置。 在您的实施中保留代码的注释和版本号可帮助 Adobe 对任何潜在问题进行疑难解答。

/******************************************* BEGIN CODE TO DEPLOY *******************************************/
/* Adobe Consulting Plugin: zeroPad v1.0 */
function zeroPad(num,nod){num=parseInt(num);nod=parseInt(nod);if(isNaN(num)||isNaN(nod))return"";var c=nod-num.toString().length+ 1;return Array(+(0<c&&c)).join("0")+num};

/* Adobe Consulting Plugin: randomNumber v2.0 (zeroPad plug-in optional)*/
function randomNumber(nod){nod="number"===typeof nod?17>Math.abs(nod)?Math.round(Math.abs(nod)):17:10;for(var a="1",c=0;c<nod;c++) a+="0";a=Number(a);a=Math.floor(Math.random().toFixed(nod)*a)+"";a.length!==nod&&"undefined"!==typeof zeroPad&&(a=zeroPad(a,nod)); return a};

/* Adobe Consulting Plugin: twoDecimals v1.0 */
function twoDecimals(v){return"undefined"===typeof v||void 0===v||isNaN(v)?0:Number(Number(v).toFixed(2))};
/******************************************** END CODE TO DEPLOY ********************************************/

使用插件

zeroPad 函数使用以下参数:

  • num(必需,整数):要填充的数字。 如果此参数的值含小数,则此函数会将该值向下取整。
  • nod(必需,整数):最终返回值的位数。 如果要填充的数字的位数少于要填充的位数,则此插件会在 num 参数的开头处添加相应数量的零。

randomNumber 函数使用以下参数:

  • nod(可选,整数):要生成的随机数的位数。 最大值为 17 位。 默认值为 10 位。

twoDecimals 函数使用以下参数:

  • val(必需,数字):要将其四舍五入到最接近的百分位值的数字(由字符串或数字对象表示)。

返回结果

  • zeroPad 函数会返回一个等于 num 参数的字符串,但会在其值的开头处添加特定数量的零,以确保返回值具有正确位数。
  • randomNumber 函数会返回一个等于具有所需位数的随机数的字符串。
  • twoDecimals 函数会返回一个已四舍五入到最接近的百分位值的数字对象。

示例调用

zeroPad 示例

s.eVar25 = zeroPad(25.5562, 5) //sets eVar25 equal to "00025"

s.prop1 = zeroPad(25, 1) //sets prop1 equal to "25"

s.prop1 = zeroPad(232425235,23) //sets prop1 equal to "00000000000000232425235"

randomNumber 示例

s.eVar65 = randomNumber(15) //sets eVar65 equal to "721759731750342" or some other random 15-digit number

randomNumber() //returns a random 10-digit number but is useless since this isn't used in an expression

var j = randomNumber(35) //sets a variable named j equal to "15476068651810060" or another random 17-digit number

twoDecimals 示例

s.events = "event10=" + twoDecimals("85.4827128694") //sets s.events="event10=85.48"

var fivehundredthirtytwo = twoDecimals(532.000000001) //sets the variable fivehundredthirtytwo equal to 532

s.eVar65 = twoDecimals("672132.9699736457") //sets s.eVar65 equal to 672132.97

版本历史记录

1.0(2019 年 5 月 25 日)

  • 第一版。
已自动翻译
使用语言选择器查看此页面的英文版本。
翻译有帮助吗?

Ask AI

Not sure where to start?
Ask me anything about Adobe products.

Type your question or pick a suggestion below.

Use of this AI chatbot is subject to Adobe's Privacy Policy. Don't share sensitive data. AI responses are not your Content, may be inaccurate, and any offers provided are non-binding. Generative AI Terms.