此外掛程式由 Adobe Consulting 提供,協助您從 Adobe Analytics 中獲得更多價值。Adobe 客戶服務不提供此外掛程式的支援,包括安裝或疑難排解在內。如果您需要與此外掛程式有關的協助,請聯絡貴組織的客戶經理。客戶經理可安排您與顧問會面以尋求協助。
cleanStr
外掛程式會移除或取代字串中所有不必要的字元,包括 HTML 標記字元、額外的空格、標記和新行/歸位字元。它也能以直式單引號 ('
) 取代左/右單引號 (‘
和 ’
)。如果您想從變數值中移除不必要的字元,Adobe建議您使用此外掛程式,而Adobe Experience Platform資料收集中的「清除文字」功能無法滿足您的實作需求。 如果收集的資料不含不必要的字元,或Adobe Experience Platform資料收集中的「清除文字」功能已足夠,則不需要此外掛程式。
如果您不想使用外掛程式擴充功能,可以使用自訂程式碼編輯器。
Analytics 追蹤物件實例化 (使用 s_gi
) 後,將下列程式碼複製並貼到 AppMeasurement 檔案中的任何位置。保留您實作中的程式碼備註和版本號碼,有助於 Adobe 疑難排解任何可能問題。
/******************************************* BEGIN CODE TO DEPLOY *******************************************/
/* Adobe Consulting Plugin: cleanStr v2.0 (No Prerequisites Required) */
function cleanStr(str){var a=str;if("-v"===a)return{plugin:"cleanStr",version:"2.0"};a:{if("undefined"!==typeof window.s_c_il){var b=0;for(var c;b<window.s_c_il.length;b++)if(c=window.s_c_il[b],c._c&&"s_c"===c._c){b=c;break a}}b=void 0}"undefined"!==typeof b&&(b.contextData.cleanStr="2.0");if("string"===typeof a){a=a.replace(/<\/?[^>]+(>|$)/g,"");a=a.trim();a=a.replace(/[\u2018\u2019\u201A]/g,"'");a=a.replace(/\t+/g,"");for(a=a.replace(/[\n\r]/g," ");-1<a.indexOf(" ");)a=a.replace(/\s\s/g," ");return a}return""}
/******************************************** END CODE TO DEPLOY ********************************************/
cleanStr
函數會使用以下引數:
str
(必要,字串):您想要清除 HTML 編碼、額外空格、定位字元或其他不必要字元的值。此函數會傳回 str
引數的值,並移除所有不必要的字元。
// Returns the value "this is a messystring". Note that both tabs and extra spaces are present in the original string.
// Multiple spaces are reduced to one, while tabs are omitted entirely.
s.eVar1 = " this is a messy string ";
s.eVar1 = cleanStr(s.eVar1)
// This function call does not do anything because the code does not assign the returned value to a variable.
s.eVar1 = " this is a messy string ";
cleanStr(s.eVar1);