使用 AppMeasurement 安装此插件

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

/******************************************* BEGIN CODE TO DEPLOY *******************************************/
/* Adobe Consulting Plugin: getPageName v4.2 */
var getPageName=function(si,qv,hv,de){var a=si,b=qv,f=hv,e=de;if("-v"===a)return{plugin:"getPageName",version:"4.2"};a:{if("undefined"!==typeof window.s_c_il){var d=0;for(var g;d<window.s_c_il.length;d++)if(g=window.s_c_il[d],g._c&&"s_c"===g._c){d=g;break a}}d=void 0}"undefined"!==typeof d&&(d.contextData.getPageName="4.2");var c=location.hostname,h=location.pathname.substring(1).split("/"),l=h.length,k=location.search.substring(1).split("&"),m=k.length;d=location.hash.substring(1).split("&");g=d.length;e=e?e:"|";a=a?a:c;b=b?b:"";f=f?f:"";if(1===l&&""===h[0])a=a+e+"home";else for(c=0;c<l;c+\+)a=a+e+decodeURIComponent(h[c]);if(b&&(1!==m||""!==k[0]))for(h=b.split(","),l=h.length,c=0;c<l;c++)for(b=0;b<m;b++)if(h[c]===k[b].split("=")[0]){a=a+e+decodeURIComponent(k[b]);break}if(f&&(1!==g||""!==d[0]))for(f=f.split(","),k=f.length,c=0;c<k;c++)for(b=0;b<g;b++)if(f[c]===d[b].split("=")[0]){a=a+e+decodeURIComponent(d[b]);break}return a.substring(a.length-e.length)===e?a.substring(0,a.length-e.length):a};
/******************************************** END CODE TO DEPLOY ********************************************/

使用此插件

getPageName 函数使用以下参数:

  • si(可选,字符串):插入到字符串开头的 ID,表示网站的 ID。此值可以是数字 ID 或友好名称。如果未设置此值,则将默认使用当前域。
  • qv(可选,字符串):以逗号分隔的查询字符串参数列表,其中包含在 URL 中找到的已添加到字符串的参数(如果可找到)
  • hv(可选,字符串):以逗号分隔的参数列表,其中包含在 URL 散列中找到的已添加到字符串的参数(如果可找到)
  • de(可选,字符串):用于拆分字符串各个部分的分隔符。默认使用管道分隔符 (|)。

此函数将返回一个包含 URL 的友好格式版本的字符串。此字符串通常会被分配给 pageName 变量,但也可以用于其他变量。

示例

// Given the URL https://mail.example.com/mail/u/0/#inbox, sets the page variable to "mail.example.com|mail|u|0".
s.pageName = getPageName();

// Given the URL https://mail.example.com/mail/u/0/#inbox, sets the page variable to "example|mail|u|0".
s.pageName = getPageName("example");

// Given the URL https://www.example.com/, sets the page variable to "www.example.com|home".
// When the code runs on a URL that does not contain a path, it always adds the value of "home" to the end of the return value.
s.pageName = getPageName();

// Given the URL https://www.example.com/, sets the page variable to "example|home".
s.pageName = getPageName("example","","","|");

// Given the URL https://www.example.com/en/booking/room-booking.html?cid=1235#/step2&arrive=05-26&depart=05-27&numGuests=2
// Sets the page variable to "www.example.com|en|booking|room-booking.html".
s.pageName = getPageName();

// Given the URL https://www.example.com/en/booking/room-booking.html?cid=1235#/step2&arrive=05-26&depart=05-27&numGuests=2
// Sets the page variable to "example: en: booking: room-booking.html: cid=1235: arrive=05-26: numGuests=2"
s.pageName = getPageName("example","cid","arrive,numGuests",": ");

从先前的版本升级

不论是否存在 Adobe Analytics 的 AppMeasurement 对象(即 s 对象),4.0 版以上的 getPageName 插件都可以正常运行。如果升级到此版本,则可从调用中删除 s 对象的所有实例来更改用于调用此插件的代码。例如,将 s.getPageName(); 更改为 getPageName();

版本历史记录

4.2(2021 年 3 月 19 日)

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

4.1(2019 年 9 月 17 日)

  • 将默认分隔符值从“冒号 + 空格”更改为管道字符。

4.0(2018 年 5 月 22 日)

  • 对插件进行了彻底的再分析/重写
上一页getPageLoadTime
下一页getPercentPageViewed

Analytics