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

如果您不想使用“常用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: getTimeParting v6.3 (No Prerequisites Needed) */
function getTimeParting(t){var c=t;if("-v"===t)return{plugin:"getTimeParting",version:"6.3"};a:{if("undefined"!==typeof window.s_c_il){var a=0;for(var b;a<window.s_c_il.length;a++)if(b=window.s_c_il[a],b._c&&"s_c"===b._c){a=b;break a}}a=void 0}"undefined"!==typeof a&&(a.contextData.getTimeParting="6.3");c=document.documentMode?void 0:c||"Etc/GMT";a=(new Date).toLocaleDateString("en-US",{timeZone:c,minute:"numeric",hour:"numeric",weekday:"long",day:"numeric",year:"numeric",month:"long"});a=/([a-zA-Z]+).*?([a-zA-Z]+).*?([0-9]+).*?([0-9]+)(.*?)([0-9])(.*)/.exec(a);return"year="+a[4]+" | month="+a[2]+" | date="+a[3]+" | day="+a[1]+" | time="+(a[6]+a[7])};
/******************************************** END CODE TO DEPLOY ********************************************/

使用此插件

getTimeParting 函数使用以下参数:

t(可选但建议使用的字符串):要将访客的本地时间转换到的时区的名称。默认为 UTC/GMT 时间。请参阅维基百科上的 TZ 时区数据库所含时区列表,以获取有效值的完整列表。

常见有效值包括:

  • "America/New_York"(表示东部时间)
  • "America/Chicago"(表示中部时间)
  • "America/Denver"(表示山地时间)
  • "America/Los_Angeles"(表示太平洋时间)

调用此函数将返回一个字符串,其中包含以竖线 (|) 分隔的以下项:

  • 当前年份
  • 当前月份
  • 当前日期
  • 星期几
  • 当前时间(上午/下午)

示例

// Use the following code if the visitor resides in Paris, France
s.eVar8 = getTimeParting("Europe/Paris");

// Use the following code if the visitor resides in San Jose, California
s.eVar17 = getTimeParting("America/Los_Angeles");

// Use the following code if the visitor resides in Ghana.
// Note that Ghana is in GMT time, the default time zone that the plug-in uses with no argument
s.eVar22 = getTimeParting();

// Internet Explorer only returns the visitor's local time. Use this conditional statement to accommodate IE visitors
if(!document.documentMode) s.eVar39 = getTimeParting("America/New_York");
else s.eVarX = "Internet Explorer Visitors";

// Given a visitor from Denver Colorado visits a site on August 31, 2020 at 9:15 AM
// Returns the string value "year=2020 | month=August | date=31 | day=Friday | time=6:15 PM"
s.eVar10 = getTimeParting("Europe/Athens");

// Returns the string value "year=2020 | month=August | date=31 | day=Friday | time=6:15 AM"
s.eVar11 = getTimeParting("America/Nome");

// Returns the string value "year=2020 | month=August | date=31 | day=Friday | time=8:45 PM"
s.eVar12 = getTimeParting("Asia/Calcutta");

// Returns the string value "year=2020 | month=September | date=1 | day=Saturday | time=1:15 AM"
s.eVar13 = getTimeParting("Australia/Sydney");

版本历史记录

6.3(2021 年 3 月 19 日)

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

6.2(2019 年 11 月 5 日)

  • 修复了若干小错误
  • 从整体上缩小了代码大小

6.1(2018 年 11 月 26 日)

  • 对 Internet Explorer 浏览器问题进行了修复。此类浏览器可以返回时间,但只能返回访客所在地区的本地时间。

6.0(2018 年 8 月 14 日)

  • 为符合国际标准,进行了彻底重写。现在可正确转换夏令时和所有时区。

5.0(2018 年 4 月 17 日)

  • 修正版本(重新编译,代码更小)
  • 由于现在可自动检测到夏令时开始/结束日期,因此无需再使用 tpDST 参数。
CAUTION
此插件的早期版本无法在将来的所有年份中使用。如果您使用此插件的早期版本,Adobe 强烈建议升级到最新版本,以避免 JavaScript 错误和数据丢失。如果无法升级此插件,请确保插件代码中的 s._tpdst 变量包含适当的将来年份。

4.0(2016 年 8 月 22 日)

  • 提供了全新的解决方案,现在可包含年份、月份和日期信息。
上一页getTimeBetweenEvents
下一页getTimeSinceLastVisit

Analytics