onBeforeEventSend

onBeforeEventSend回呼可讓您註冊JavaScript函式,該函式可變更您在傳送資料至Adobe之前所傳送的資料。 此回呼可讓您操作xdmdata物件,包括新增、編輯或移除元素的功能。 您也可以有條件地完全取消傳送資料,例如使用偵測到的使用者端機器人流量。

WARNING
此回呼允許使用自訂程式碼。 如果您包含在回撥中的任何程式碼擲回未攔截到的例外狀況,則處理事件會暫停,而且不會將​資料傳送至Adobe。

執行onBeforeEventSend命令時登入configure回呼。 您可以透過變更內嵌函式內的引數變數,將content變數名稱變更為任何您想要的值。

alloy("configure", {
  datastreamId: "ebebf826-a01f-4458-8cec-ef61de241c93",
  orgId: "ADB3LETTERSANDNUMBERS@AdobeOrg",
  onBeforeEventSend: function(content) {
    // Use nullish coalescing assignments to add a new value
    content.xdm._experience ??= {};
    content.xdm._experience.analytics ??= {};
    content.xdm._experience.analytics.customDimensions ??= {};
    content.xdm._experience.analytics.customDimensions.eVars ??= {};
    content.xdm._experience.analytics.customDimensions.eVars.eVar1 = "Analytics custom value";

    // Use optional chaining to change an existing value
    if(content.xdm.web?.webPageDetails) content.xdm.web.webPageDetails.URL = content.xdm.web.webPageDetails.URL.toLowerCase();

    // Remove an existing value
    if(content.xdm.web?.webReferrer) delete content.xdm.web.webReferrer.URL;

    // Return true to immediately send data
    if (sendImmediate == true) {
      return true;
    }

    // Return false to immediately cancel sending data
    if(myBotDetector.isABot()){
      return false;
    }

    // Assign the value in the 'cid' query string to the tracking code XDM element
    content.xdm.marketing ??= {};
    content.xdm.marketing.trackingCode = new URLSearchParams(window.location.search).get('cid');
  }
});

您也可以註冊自己的函式,而非內嵌函式。

function lastChanceLogic(content) {
  content.xdm.application ??= {};
  content.xdm.application.name = "App name";
}

alloy("configure", {
  datastreamId: "ebebf826-a01f-4458-8cec-ef61de241c93",
  orgId: "ADB3LETTERSANDNUMBERS@AdobeOrg",
  onBeforeEventSend: lastChanceLogic
});

使用Web SDK標籤擴充功能設定「在事件傳送回呼之前」

可以使用資料收集組態設定,在網頁SDK標籤擴充功能中設定這些設定。

recommendation-more-help
1ae86b30-e55e-49c1-ab11-9d0356a5f3e1