此外掛程式由 Adobe Consulting 提供,協助您從 Adobe Analytics 中獲得更多價值。Adobe 客戶服務不提供此外掛程式的支援,包括安裝或疑難排解在內。如果您需要與此外掛程式有關的協助,請聯絡貴組織的 Adobe 客戶團隊。他們可幫您安排顧問會議,以尋求協助。
getPreviousValue
外掛程式可讓您將變數設定為先前點擊上設定的值。如果您的實施包含目前點擊中的所有所需值,就不需要此外掛程式。
Adobe提供的擴充功能可讓您將最常用的外掛程式與Web SDK搭配使用。
getPreviousValue
手動實作Web SDK時尚不支援此外掛程式。
Adobe提供的擴充功能可讓您搭配Adobe Analytics使用最常用的外掛程式。
如果您不想使用常見Analytics外掛程式擴充功能,可以使用自訂程式碼編輯器。
Analytics 追蹤物件實例化 (使用 s_gi
) 後,將下列程式碼複製並貼到 AppMeasurement 檔案中的任何位置。保留您實作中的程式碼備註和版本號碼,有助於 Adobe 疑難排解任何可能問題。
/* Adobe Consulting Plugin: getPreviousValue v3.0 */
function getPreviousValue(v,c){var k=v,d=c;if("-v"===k)return{plugin:"getPreviousValue",version:"3.0"};var a=function(){if("undefined"!==typeof window.s_c_il)for(var c=0,b;c<window.s_c_il.length;c++)if(b=window.s_c_il[c],b._c&&"s_c"===b._c)return b}();"undefined"!==typeof a&&(a.contextData.getPreviousValue="3.0");window.cookieWrite=window.cookieWrite||function(c,b,f){if("string"===typeof c){var h=window.location.hostname,a=window.location.hostname.split(".").length-1;if(h&&!/^[0-9.]+$/.test(h)){a=2<a?a:2;var e=h.lastIndexOf(".");if(0<=e){for(;0<=e&&1<a;)e=h.lastIndexOf(".",e-1),a--;e=0<e?h.substring(e):h}}g=e;b="undefined"!==typeof b?""+b:"";if(f||""===b)if(""===b&&(f=-60),"number"===typeof f){var d=new Date;d.setTime(d.getTime()+6E4*f)}else d=f;return c&&(document.cookie=encodeURIComponent(c)+"="+encodeURIComponent(b)+"; path=/;"+(f?" expires="+d.toUTCString()+";":"")+(g?" domain="+g+";":""),"undefined"!==typeof cookieRead)?cookieRead(c)===b:!1}};window.cookieRead=window.cookieRead||function(c){if("string"===typeof c)c=encodeURIComponent(c);else return"";var b=" "+document.cookie,a=b.indexOf(" "+c+"="),d=0>a?a:b.indexOf(";",a);return(c=0>a?"":decodeURIComponent(b.substring(a+2+c.length,0>d?b.length:d)))?c:""};var l;d=d||"s_gpv";a=new Date;a.setTime(a.getTime()+18E5);window.cookieRead(d)&&(l=window.cookieRead(d));k?window.cookieWrite(d,k,a):window.cookieWrite(d,l,a);return l};
/******************************************** END CODE TO DEPLOY ********************************************/
getPreviousValue
函數會使用以下引數:
v
(字串,必要):具有您要傳遞至下一個影像要求之值的變數。用來擷取上一頁值的通用變數為 s.pageName
。c
(字串,選用):儲存值的 Cookie 名稱。如果未設定此引數,其預設值為 "s_gpv"
。當您呼叫此方法時,它會傳回 Cookie 中包含的字串值。 此外掛程式會重設 Cookie 有效期,並從 v
引數指派變數值。閒置 30 分鐘後,Cookie 便會到期。
// 1. Sets prop7 to the cookie value contained in gpv_Page
// 2. Resets the gpv_Page cookie value to the page variable
// 3. If the page variable is not set, reset the gpv_Page cookie expiration
s.prop7 = getPreviousValue(s.pageName,"gpv_Page");
// Sets prop7 to the cookie value contained in gpv_Page, but only if event1 is in the events variable.
if(inList(s.events,"event1")) s.prop7 = getPreviousValue(s.pageName,"gpv_Page");
// Sets prop7 to the cookie value contained in gpv_Page, but only if the page variable is currently set on the page
if(s.pageName) s.prop7 = getPreviousValue(s.pageName,"gpv_Page");
// Sets eVar10 equal to the cookie value contained in s_gpv, then sets the s_gpv cookie to the current value of eVar1.
s.eVar10 = getPreviousValue(s.eVar1);
如果將與 v
引數相關聯的變數設為新值,且 getPreviousValue
外掛程式執行中,但未同時傳送 Analytics 伺服器呼叫,則下次外掛程式執行時,新的 v
引數值仍會被視為「上一個值」。
例如,假設下列程式碼會在造訪的第一頁上執行:
s.pageName = "Home";
s.prop7 = getPreviousValue(s.pageName,"gpv_Page");
s.t();
此程式碼會產生伺服器呼叫,其中 pageName
為「Home」且未設定 prop7。 然而,getPreviousValue
的呼叫會將 pageName
的值儲存在 gpv_Page
Cookie 中。 假設下列程式碼緊接著在相同頁面上執行:
s.pageName = "New value";
s.prop7 = getPreviousValue(s.pageName,"gpv_Page");
由於 t()
函數並未在此程式碼區塊中執行,因此不會傳送另一個影像要求。 然而,這次執行 getPreviousValue
函數程式碼時,prop7
設定為 pageName
的上一個值 (「Home」),然後將 pageName
的新值 (「New value」) 儲存在 gpv_Page
Cookie 中。 接下來,假設訪客導覽至另一個頁面,且在此頁面上執行下列程式碼:
s.pageName = "Page 2";
s.prop7 = getPreviousValue(s.pageName,"gpv_Page");
s.t();
當 t()
函數執行時,它會建立影像要求,其中 pageName
為「Page 2」,且 prop7
為「New value」,也就是上次呼叫 getPreviousValue
時的 pageName
值。 雖然「Home」是傳遞給 pageName
的第一個值,但是影像要求中從未包含 "Home"
的 prop7
值。