此插件由 Adobe Consulting 团队提供,旨在帮助您从 Adobe Analytics 中获取更多的价值。Adobe 客户关怀团队不提供对此插件的支持,包括安装或疑难解答。如果您需要关于此插件的帮助,请与贵组织的帐户管理员联系。他们可以为您安排与顾问的答疑会,以便您向顾问寻求帮助。
apl
插件允许您安全地向已列表分隔的变量(如 events
、linkTrackVars
、list
和其他变量)添加新值。
如果要向现有变量添加新值,并且现有变量包含由分隔值构成的字符串,Adobe 建议使用此插件。如果您要为包含分隔值的变量连接字符串,则不需要使用此插件。
如果您不想使用插件扩展,则可以使用自定义代码编辑器。
在实例化(使用 s_gi
)Analytics 跟踪对象后,将以下代码复制并粘贴到 AppMeasurement 文件中的任意位置。在您的实施中保留代码的注释和版本号可帮助 Adobe 对任何潜在问题进行疑难解答。
/******************************************* BEGIN CODE TO DEPLOY *******************************************/
/* Adobe Consulting Plugin: apl (appendToList) v4.0 */
function apl(lv,va,d1,d2,cc){var b=lv,d=va,e=d1,c=d2,g=cc;if("-v"===b)return{plugin:"apl",version:"4.0"};var h=function(){if("undefined"!==typeof window.s_c_il)for(var k=0,b;k<window.s_c_il.length;k++)if(b=window.s_c_il[k],b._c&&"s_c"===b._c)return b}();"undefined"!==typeof h&&(h.contextData.apl="4.0");window.inList=window.inList||function(b,d,c,e){if("string"!==typeof d)return!1;if("string"===typeof b)b=b.split(c||",");else if("object"!==typeof b)return!1;c=0;for(a=b.length;c<a;c++)if(1==e&&d===b[c]||d.toLowerCase()===b[c].toLowerCase())return!0;return!1};if(!b||"string"===typeof b){if("string"!==typeof d||""===d)return b;e=e||",";c=c||e;1==c&&(c=e,g||(g=1));2==c&&1!=g&&(c=e);d=d.split(",");h=d.length;for(var f=0;f<h;f++)window.inList(b,d[f],e,g)||(b=b?b+c+d[f]:d[f])}return b};
/******************************************** END CODE TO DEPLOY ********************************************/
apl
函数使用以下参数:
lv
(必需,字符串):包含要向其添加新值的已分隔列表的变量vta
(必需,字符串):要添加到 lv
参数值的以逗号分隔的新值列表。d1
(可选,字符串):用于分隔已包含在 lv
参数中的各个值的分隔符。如果未设置,则将默认使用逗号 (,
)。d2
(可选,字符串):输出分隔符。如果未设置,则默认值与 d1
的值相同。cc
(可选,布尔值):指示是否使用区分大小写检查的标志。如果为 true
,则重复检查区分大小写。如果为 false
或未设置,则重复检查不区分大小写。默认为 false
。apl
函数会返回 lv
参数的值以及 vta
参数中的任何非重复值。
// Set the events variable to "event22,event24,event23".
s.events = "event22,event24";
s.events = apl(s.events,"event23");
// The events variable remains unchanged because the apl function does not add duplicate values
s.events = "event22,event23";
s.events = apl(s.events,"event23");
// Set the events variable to "event23" if the events variable is blank
s.events = "";
s.events = apl(s.events,"event23");
// Append a value to eVar5. The value of prop4 remains unchanged.
// The value of eVar5 is "hello|people|today".
s.prop4 = "hello|people";
s.eVar5 = apl(s.prop4, "today", "|");
// Sets prop4 to "hello|people,today". Be mindful of correct delimiters!
s.prop4 = "hello|people";
s.prop4 = apl(s.prop4, "today");
// Sets the events variable to "event22,event23,EVentT23". Be mindful of capitalization when using the cc argument!
s.events = "event22,event23";
s.events = apl(s.events,"EVenT23", ",", ",", true);
// Sets the events variable to "event22,event23,event24,event25".
s.events = "event22,event23";
s.events = apl(s.events, "event23,event24,event25");
// Sets linkTrackVars to "events,eVar1,campaign".
// The last three arguments at the end of this apl call are not necessary because they match the default argument values.
s.linkTrackVars = "events,eVar1";
s.linkTrackVars = apl(s.linkTrackVars, "campaign", ",", ",", false);
// This apl call does not do anything because the code does not assign the returned value to a variable.
s.events = "event22,event24";
apl(s.events, "event23");
// Sets the list2 variable to "apple-APPLE-Apple".
// Since the two delimiter arguments are different, the value passed in is delimited by "|", then joined together by "-".
s.list2 = "apple|APPLE";
s.list2 = apl(s.list2, "Apple", "|", "-", true);
// Sets the list3 variable to "value1,value1,value1" (unchanged).
// Only new values are deduplicated. Existing duplicate values remain.
s.list3 = "value1,value1,value1";
s.list3 = apl(s.list3,"value1");
apl
调用存在的兼容性问题inList 2.1
d2
参数现在默认为 d1
参数的值vta
参数现在一次可接受多个值d2
参数以设置返回值的格式cc
参数更改为布尔值inList
函数进行比较处理d
(分隔符)参数现在为可选参数(默认为逗号)u
(区分大小写标记)参数现在为可选参数(默认为不区分大小写)u
(区分大小写标记)参数为何值,如果该值已存在于列表中,则插件都不会再向列表附加值