此外掛程式由 Adobe Consulting 提供,協助您從 Adobe Analytics 中獲得更多價值。Adobe 客戶服務不提供此外掛程式的支援,包括安裝或疑難排解在內。如果您需要與此外掛程式有關的協助,請聯絡貴組織的 Adobe 客戶團隊。他們可幫您安排顧問會議,以尋求協助。
getPageName
外掛程式可為目前的 URL 建立易讀、好記的格式化版本。如果您想要在報表中輕鬆設定且理解的 pageName
值,Adobe 建議使用此外掛程式。如果您已有 pageName
變數的命名結構 (例如透過資料層),就不需要此外掛程式。若您沒有其他解決方案可設定 pageName
變數,最好使用此外掛程式。
Adobe提供的擴充功能可讓您將最常用的外掛程式與Web SDK搭配使用。
getPageName
手動實作Web SDK時尚不支援此外掛程式。
Adobe提供的擴充功能可讓您搭配Adobe Analytics使用最常用的外掛程式。
如果您不想使用常見Analytics外掛程式擴充功能,可以使用自訂程式碼編輯器。
Analytics 追蹤物件實例化 (使用 s_gi
) 後,將下列程式碼複製並貼到 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 雜湊中找到的逗號分隔參數清單,若在 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",": ");
getPageName
外掛程式的 4.0+ 版不取決於 Adobe Analytics AppMeasurement 物件 (即「s
」物件) 的存在。 如果您升級至此版本,請務必移除呼叫中 s
物件的任何實例,以變更呼叫該外掛程式的程式碼。 例如,將 s.getPageName();
變更為 getPageName();
。