Adobe 外掛程式:getPageName

IMPORTANT
此外掛程式由 Adobe Consulting 提供,協助您從 Adobe Analytics 中獲得更多價值。Adobe 客戶服務不提供此外掛程式的支援,包括安裝或疑難排解在內。如果您需要與此外掛程式有關的協助,請聯絡貴組織的 Adobe 客戶團隊。他們可幫您安排顧問會議,以尋求協助。

getPageName 外掛程式可為目前的 URL 建立易讀、好記的格式化版本。如果您想要在報表中輕鬆設定且理解的 pageName 值,Adobe 建議使用此外掛程式。如果您已有 pageName 變數的命名結構 (例如透過資料層),就不需要此外掛程式。若您沒有其他解決方案可設定 pageName 變數,最好使用此外掛程式。

使用Web SDK擴充功能安裝外掛程式

Adobe提供擴充功能,可讓您搭配Web SDK使用最常用的外掛程式。

  1. 使用您的 AdobeID 認證登入 Adobe Experience Platform 資料彙集

  2. 按一下 標籤 然後,按一下所需的標籤屬性。

  3. 按一下 擴充功能 然後按一下左側的 目錄 標籤

  4. 找到並安裝 常見Web SDK外掛程式 副檔名。

  5. 按一下 資料元素 然後按一下所需的資料元素。

  6. 使用下列設定來設定所需的資料元素名稱:

    • 擴充功能:常見Web SDK外掛程式
    • 資料元素: getPageName
  7. 在右側設定所要的引數。

  8. 儲存並發佈資料元素的變更。

手動實作Web SDK安裝外掛程式

此外掛程式尚不支援在Web SDK的手動實作中使用。

使用Adobe Analytics擴充功能安裝外掛程式

Adobe提供擴充功能,可讓您搭配Adobe Analytics使用最常用的外掛程式。

  1. 使用您的 AdobeID 認證登入 Adobe Experience Platform 資料彙集

  2. 按一下所需的標籤屬性。

  3. 前往擴充功能標記,然後按一下「目錄」按鈕

  4. 安裝並發佈常用 Analytics 外掛程式擴充功能

  5. 如果您尚未執行上述步驟,請使用下列設定建立標示為「初始化外掛程式」的規則:

    • 條件:無
    • 事件:核心 - 已載入資料庫 (頁面頂端)
  6. 使用下列設定將動作新增至上述規則:

    • 擴充功能:常用 Analytics 外掛程式
    • 動作類型:初始化 getPageName
  7. 儲存並發佈規則的變更。

使用自訂程式碼編輯器安裝外掛程式

如果您不想使用常見Analytics外掛程式擴充功能,可以使用自訂程式碼編輯器。

  1. 使用您的 AdobeID 認證登入 Adobe Experience Platform 資料彙集
  2. 按一下所需的屬性。
  3. 前往擴充功能索引標籤,然後按一下 Adobe Analytics 擴充功能底下的​ 「設定」 ​按鈕。
  4. 展開使用自訂程式碼設定追蹤摺疊式功能表,便會顯示「開啟編輯器」按鈕。
  5. 開啟自訂程式碼編輯器,並將下方提供的外掛程式程式碼貼入編輯視窗中。
  6. 儲存並發佈 Analytics 擴充功能的變更。

使用 AppMeasurement 安裝外掛程式

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();

版本記錄

4.2 (2021 年 3 月 19 日)

  • 將版本編號加入為內容資料。

4.1 (2019 年 9 月 17 日)

  • 將預設分隔字元值變更為縱線字元 (原為冒號 + 空格)。

4.0 (2018 年 5 月 22 日)

  • 外掛程式全面重新分析/重寫
recommendation-more-help
b4f6d761-4a8b-4322-b801-c85b9e3be690