使用自定义代码编辑器安装此插件

如果您不想使用“常用Analytics插件”插件扩展,则可以使用自定义代码编辑器。

  1. 使用您的 Adobe ID 凭据登录 Adobe Experience Platform 数据收集
  2. 单击所需的属性。
  3. 转到扩展选项卡,然后单击 Adobe Analytics 扩展下的​ 配置 ​按钮。
  4. 展开使用自定义代码配置跟踪折叠面板,这会显示打开编辑器按钮。
  5. 打开自定义代码编辑器,并将下面提供的插件代码粘贴到编辑窗口中。
  6. 保存并发布对此 Analytics 扩展所做的更改。

使用 AppMeasurement 安装此插件

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

/******************************************* BEGIN CODE TO DEPLOY *******************************************/
/* Adobe Consulting Plugin: getAndPersistValue v3.0 (Requires AppMeasurement) */
function getAndPersistValue(vtp,cn,ex){var d=vtp,k=cn,l=ex;if("undefined"!==typeof d&&"-v"===d)return{plugin:"getAndPersistValue",version:"3.0"};var a=function(){if("undefined"!==typeof window.s_c_il)for(var c=0,b;c<window.s_c_il.length;c++)if(b=window.s_c_il[c],b._c&&"s_c"===b._c)return b}();"undefined"!==typeof a&&(a.contextData.getAndPersistValue="3.0");window.cookieWrite=window.cookieWrite||function(c,b,f){if("string"===typeof c){var h=window.location.hostname,a=window.location.hostname.split(".").length-1;if(h&&!/^[0-9.]+$/.test(h)){a=2<a?a:2;var e=h.lastIndexOf(".");if(0<=e){for(;0<=e&&1<a;)e=h.lastIndexOf(".",e-1),a--;e=0<e?h.substring(e):h}}g=e;b="undefined"!==typeof b?""+b:"";if(f||""===b)if(""===b&&(f=-60),"number"===typeof f){var d=new Date;d.setTime(d.getTime()+6E4*f)}else d=f;return c&&(document.cookie=encodeURIComponent(c)+"="+encodeURIComponent(b)+"; path=/;"+(f?" expires="+d.toUTCString()+";":"")+(g?" domain="+g+";":""),"undefined"!==typeof cookieRead)?cookieRead(c)===b:!1}};window.cookieRead=window.cookieRead||function(c){if("string"===typeof c)c=encodeURIComponent(c);else return"";var b=" "+document.cookie,a=b.indexOf(" "+c+"="),d=0>a?a:b.indexOf(";",a);return(c=0>a?"":decodeURIComponent(b.substring(a+2+c.length,0>d?b.length:d)))?c:""};a=new Date;k=k?k:"s_gapv";(l=l?l:0)?a.setTime(a.getTime()+864E5*l):a.setTime(a.getTime()+18E5);"undefined"!==typeof d&&d||(d=cookieRead(k));cookieWrite(k,d,a);return d};
/******************************************** END CODE TO DEPLOY ********************************************/

使用此插件

getAndPersist 函数使用以下参数:

  • vtp(必需):要在页面之间保留的值
  • cn(可选):用于存储值的 Cookie 的名称。如果未设置此参数,则将 Cookie 命名为 "s_gapv"
  • ex(可选):Cookie 过期前的天数。如果此参数为 0 或未设置,则 Cookie 将在访问结束时过期(处于不活动状态 30 分钟)。

如果已设置 vtp 参数中的变量,则插件会设置 Cookie,然后返回 Cookie 值。如果未设置 vtp 参数中的变量,则插件只会返回 Cookie 值。

示例

// Sets eVar21 to "raccoon", and sets the ev21gapv cookie to "raccoon" (which expires in 28 days).
s.eVar21 = "raccoon";
s.eVar21 = getAndPersistValue(s.eVar21,"ev21gapv",28);

// Checks the "ev21gapv" cookie for a value and assigns it to eVar21. It does not set a cookie value or reset an existing cookie's expiration since the value is not set on the page.
// If there is a cookie, assigns eVar21 to that value. Otherwise, eVar21 is blank.
s.eVar21 = getAndPersistValue(s.eVar21,"ev21gapv",28);

// Checks the "ev21gapv" cookie for a value and assigns it to prop35. It does not set a cookie value or reset an existing cookie's expiration since eVar21 is not set on the page.
s.prop35 = getAndPersistValue(s.eVar21,"ev21gapv",28);

// Sets eVar21 to "panda", and sets the ev21gapv cookie to "panda" (which expires in 14 days). It then sets prop35 to the value contained in the ev21gapv cookie.
// Ultimately both eVar21 and prop35 contain the value "panda".
s.eVar21 = "panda";
s.prop35 = getAndPersistValue(s.eVar21,"ev21gapv",14);

// Sets eVar30 to "shopping", and sets the s_gapv cookie to "shopping" (which expires at the end of the browser session).
s.eVar30 = "shopping";
s.eVar30 = getAndPersistValue(s.eVar30);

版本历史记录

3.0(2021 年 3 月 19 日)

  • 以上下文数据形式添加了版本号。

2.0(2018 年 4 月 16 日)

  • 修正版本(代码更小)
  • 现在,将 0 传递到 ex 参数将强制执行 30 分钟处于不活动状态后过期,而不是在浏览器会话结束时过期。

1.0(2016 年 1 月 18 日)

  • 第一版。
上一页formatTime
下一页getGeoCoordinates

Analytics