如何将utm标签添加到wix表单?

问题描述 投票:0回答:1

我目前正在尝试将 UTM 标签包含在我从 wix 表单发送的 webhook 中。但是,在发送网络钩子后,我要么收到空响应,要么收到“google.co.il”源。我特别期待 Google Ads 或电子邮件来源。 我添加了我正在使用的代码,试图正确地实现此功能。任何帮助或指导将不胜感激..

 

export function wixForms1_wixFormSubmitted(event) {
    var obj = {};
    var i = 0;
    for (i=0;i<event.fields.length;i++){
        obj[event.fields[i].id] = event.fields[i].fieldValue;
    }
    //console.log(obj);
    fetch( "https://hook.eu1.make.com/62tsltjotop6iwboufggguuxhhqrjaen", {
    "method": "post",
    "headers": {
        "Content-Type": "application/json"
    },
    "body": JSON.stringify(obj)
    } )
    .then( (httpResponse) => {
        if (httpResponse.ok) {
        return httpResponse.json();
        } else {
        return Promise.reject("Fetch did not succeed");
        }
    } )
    .then( (json) => console.log(json) )
    .catch(err => console.log(err));
}

$w.onReady(function () {
    const query = wixLocation.query;
        if (query) {
            $w('#refbox').value = JSON.stringify(query);
        }
 let params = wixLocation.query
    console.log(params)
    $w('#campaign').value = params.campaign_name
    $w('#source').value = params.utm_source
    });
import wixWindow from 'wix-window';
import wixLocation from 'wix-location';
 
});
import wixWindow from 'wix-window';
import wixLocation from 'wix-location';
import {local, session, memory} from 'wix-storage';
 
let referrer = wixWindow.referrer;
let previousPageURL;
 
$w.onReady(function () {
 previousPageURL = session.getItem("page");
 session.setItem("page", wixLocation.url);
});
 
 
$w.onReady(function () {
    // Write your JavaScript here
    const prvurl = wixLocation.url;
        if (prvurl) {
            $w('#prvurl').value = JSON.stringify(prvurl);
    
        }
 
 
    // To select an element by ID use: $w("#elementID")
 
    // Click "Preview" to run your code
        const query = wixWindow.referrer;
        if (query) {
            $w('#refbox').value = JSON.stringify(query);
    
        }
    
 
 
}
);

webhooks velo utm-tracking
1个回答
0
投票

您必须在表单上创建字段,例如

cf_utm_campaign
cf_utm_medium
等,并将其隐藏(使用样式)。

之后,添加此自定义脚本:

    <script>
    
        // Get the current URL
        var currentUrl = window.location.href;
    
        // Define an object with mappings of variables to corresponding text fields
        var fieldMappings = {
            utm_campaign: 'cf_utm_campaign',
            utm_content: 'cf_utm_content',
            utm_medium: 'cf_utm_medium',
            utm_source: 'cf_utm_source',
            utm_term: 'cf_utm_term'
        };
    
        // Loop through the mappings and insert the values into the corresponding text fields
        for (var param in fieldMappings) {
            var fieldName = fieldMappings[param];
            var match = currentUrl.match(new RegExp('[?&]' + param + '=([^&]+)'));
    
            if (match) {
                var paramValue = match[1];
                var textField = document.querySelector('input[name="' + fieldName + '"]');
    
                if (textField) {
                    textField.value = paramValue;
                }
            }
        }
        
    </script>

这将使用位置 url 接收到的值来“补充”您的字段。

© www.soinside.com 2019 - 2024. All rights reserved.