簡體   English   中英

表單放棄數據Google標記管理器

[英]Form Abandonment data google tag manager

用於Google跟蹤代碼管理器中的表單放棄跟蹤。 以下是代碼(來自http://www.simoahava.com/analytics/track-form-abandonment-with-google-tag-manager/的原始代碼)。 我已根據我的要求修改了代碼。

    (function() {
    var formSelector = '.webform-component-fieldset';
    var attribute = 'name';
    var history = [];
    window.addEventListener('beforeunload', function() {
        if (history.length) {
            var x = history.join(' > ');
            var x= x.replace(/submitted[fieldset_user_info]/g,"");
            window.dataLayer.push({
                'event' : 'formAbandonment',
                'category' : 'Form Abandonment',
                'action' : x

            });
        };
    });
});

 document.querySelector(formSelector).addEventListener('change', function(e) {
    history.push(e['target'].getAttribute(attribute));
});
})();

該代碼正在執行,但是不需要輸出。 我為eventAction數據層('action':x)獲得的輸出如下

提交的[fieldset_user_info] [名字]>提交的[fieldset_user_info] [街道名稱_1]>提交的[fieldset_user_info] [街道名稱_2]>提交的[fieldset_user_info] [城市]>提交的[fieldset_user_info] [狀態]>提交的[fieldset_user_info] [zip_code]>提交的[ fieldset_user_info] [電子郵件地址]>已提交[fieldset_user_info] [confirm_e_mail_address]>已提交[fieldset_user_info] [last_name]>已提交[fieldset_user_info] [street_address_2]>已提交[fieldset_user_info] [i_prefer_to_receive_communications_from_pfizer_by

我想從輸出中刪除每次出現的文本“ submitted [fieldset_user_info]”,但是使用上面的代碼,我無法執行

修改代碼是否需要任何幫助。

嘗試替換字符串

var x= x.replace(/submitted[fieldset_user_info]/g,"");

按字符串:

var x= x.replace("submitted[fieldset_user_info]","");

根據JS replace()方法描述,它支持正則表達式以及字符串作為第一個參數。

我嘗試在控制台中測試“ replace()”方法有兩種變體:使用RegEx和簡單的string:方法僅可成功使用字符串。 可能是您的regEx有問題(對我而言,這看起來是正確的)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM