Adobe 外掛程式:getGeoCoordinates

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

getGeoCoordinates 外掛程式可讓您擷取訪客裝置的經緯度。如果您想要在 Analytics 變數中擷取地理位置資料,Adobe 建議您使用此外掛程式。

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

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

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

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

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

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

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

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

    • 擴充功能:常見Web SDK外掛程式
    • 資料元素: getGeoCoordinates
  7. 儲存並發佈資料元素的變更。

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

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

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

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

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

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

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

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

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

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

    • 擴充功能:常用 Analytics 外掛程式
    • 動作類型:初始化 getGeoCoordinates
  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: getGeoCoordinates v2.0  */
function getGeoCoordinates(){if(arguments&&"-v"===arguments[0])return{plugin:"getGeoCoordinates",version:"2.0"};var b=function(){if("undefined"!==typeof window.s_c_il)for(var a=0,c;a<window.s_c_il.length;a++)if(c=window.s_c_il[a],c._c&&"s_c"===c._c)return c}();"undefined"!==typeof b&&(b.contextData.getGeoCoordinates="2.0");window.cookieWrite=window.cookieWrite||function(a,c,f){if("string"===typeof a){var h=window.location.hostname,b=window.location.hostname.split(".").length-1;if(h&&!/^[0-9.]+$/.test(h)){b=2<b?b:2;var e=h.lastIndexOf(".");if(0<=e){for(;0<=e&&1<b;)e=h.lastIndexOf(".",e-1),b--;e=0<e?h.substring(e):h}}g=e;c="undefined"!==typeof c?""+c:"";if(f||""===c)if(""===c&&(f=-60),"number"===typeof f){var d=new Date;d.setTime(d.getTime()+6E4*f)}else d=f;return a&&(document.cookie=encodeURIComponent(a)+"="+encodeURIComponent(c)+"; path=/;"+(f?" expires="+d.toUTCString()+";":"")+(g?" domain="+g+";":""),"undefined"!==typeof cookieRead)?cookieRead(a)===c:!1}};window.cookieRead=window.cookieRead||function(a){if("string"===typeof a)a=encodeURIComponent(a);else return"";var c=" "+document.cookie,b=c.indexOf(" "+a+"="),d=0>b?b:c.indexOf(";",b);return(a=0>b?"":decodeURIComponent(c.substring(b+2+a.length,0>d?c.length:d)))?a:""};var d="";b=cookieRead("s_ggc").split("|");var k={timeout:5E3,maximumAge:0},l=function(a){a=a.coords;cookieWrite("s_ggc",parseFloat(a.latitude.toFixed(4))+"|"+parseFloat(a.longitude.toFixed(4)),30);d="latitude="+parseFloat(a.latitude.toFixed(4))+" | longitude="+parseFloat(a.longitude.toFixed(4))},m=function(a){d="error retrieving geo coordinates"};1<b.length&&(d="latitude="+b[0]+" | longitude="+b[1]);navigator.geolocation&&navigator.geolocation.getCurrentPosition(l,m,k);""===d&&(d="geo coordinates not available");return d};
/******************************************** END CODE TO DEPLOY ********************************************/

使用外掛程式

getGeoCoordinates 函數不使用任何引數。 它會傳回以下其中一個值:

  • "geo coordinates not available":針對外掛程式執行時沒有地理位置資料的裝置。此值在造訪的第一次點擊時很常見,尤其是當訪客需要先同意追蹤其位置的情況下。
  • "error retrieving geo coordinates":當外掛程式嘗試擷取裝置位置時遇到任何錯誤時
  • "latitude=[LATITUDE] | longtitude=[LONGITUDE]":其中的 [LATITUDE]/[LONGITUDE] 分別代表緯度與經度
NOTE
座標值會四捨五入到小數點後第四位最接近的值。例如,"40.438635333" 值會四捨五入為 "40.4386",藉此限制要擷取的獨特值數目。這些值足以精準定位 20 英尺內裝置的確切位置。

需要的話,此外掛程式會使用名為 "s_ggc" 的 Cookie 來儲存點擊之間的座標。

範例

// Sets eVar1 to one of the above return values depending on the visitor's device status.
s.eVar1 = getGeoCoordinates();

// Extracts latitude and longitude into their own variables called finalLatitude and finalLongitude for use in other code/applications.
var coordinates = getGeoCoordinates();
if(coordinates.indexOf("latitude") > -1)
{
  var finalLatitude = Number(coordinates.split("|")[0].trim().split("=")[1]),
  finalLongitude = Number(coordinates.split("|")[1].trim().split("=")[1]);
}

// From there, you can determine whether a visitor is at, for example, the Statue of Liberty:
if(finalLatitude >= 40.6891 && finalLatitude <= 40.6893 && finalLongitude >= -74.0446 && finalLongitude <= -74.0444)
{
  var visitorAtStatueOfLiberty = true;
}
else
{
  var visitorAtStatueOfLiberty = false;
}

版本記錄

2.0 (2021 年 3 月 19 日)

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

1.0 (2015 年 5 月 25 日)

  • 首次發行。
recommendation-more-help
b4f6d761-4a8b-4322-b801-c85b9e3be690