如何为Wix表单添加onclick事件以触发Bing转化统计
Hey there! Let's break down how to set up Bing conversion tracking for your Wix subscription form, since you're familiar with HTML/JS but new to Wix Code. I'll cover both native Wix forms and custom HTML forms, plus key notes for your A/B testing setup:
1. First: Grab Your Bing Conversion Tracking Code
Head to your Bing Ads dashboard to get your unique conversion snippet. It'll look something like this (replace placeholders with your actual conversion ID and details):
window.uetq = window.uetq || []; window.uetq.push('event', 'YOUR_CONVERSION_ID', { 'revenue': 0.0, // Set to your conversion value if applicable; leave 0 if no value 'currency': 'USD' // Update to your currency code });
Keep this handy—you'll need it in the next steps.
2. For Native Wix Subscription Forms
Wix's built-in forms don't let you directly edit the button's onclick attribute, but we can use Wix Code's event listeners to hook into the form submission:
- Open your homepage in the Wix Editor, then click the Code button (or press
Ctrl+Shift+I) and select Page Code (make sure it's linked to your homepage). - In the
onReadyfunction, add a listener for the form'sonAfterSubmitevent (this fires only after the form successfully submits, avoiding false conversions). Replace#emailSubscriptionFormwith your form's actual ID (find this in the right-side Properties panel when you select the form):$w.onReady(function () { // Listen for successful form submission $w("#emailSubscriptionForm").onAfterSubmit( () => { // Trigger Bing conversion tracking window.uetq = window.uetq || []; window.uetq.push('event', 'YOUR_CONVERSION_ID', { 'revenue': 0.0, 'currency': 'USD' }); }); });
A/B Testing Note for Native Forms
If you're running Wix's built-in A/B tests for your homepage, make sure to add this code to both variant pages, or place it in your Site Code (under the Code menu) so it applies to all page versions automatically.
3. For Custom HTML Embedded Forms
If you added your subscription form using Wix's Embed HTML component (your own custom HTML/JS), you can directly modify the button's onclick to trigger the conversion code:
Update your form code to combine form submission logic with Bing tracking:
<form id="customSubForm"> <input type="email" id="userEmail" required placeholder="Enter your email"> <!-- Modified submit button --> <button type="button" onclick="handleSubscription()">Subscribe</button> </form> <script> function handleSubscription() { const email = document.getElementById('userEmail').value; // First: Handle your form submission logic // (e.g., send data to Wix Data, your backend, or use form action) // Then: Trigger Bing conversion tracking window.uetq = window.uetq || []; window.uetq.push('event', 'YOUR_CONVERSION_ID', { 'revenue': 0.0, 'currency': 'USD' }); // Optional: Submit the form if using traditional form action document.getElementById('customSubForm').submit(); } </script>
4. Verify It's Working
- Use Bing Ads' Conversion Tracking Validation Tool to test: Visit your homepage, submit the form, and confirm the tool detects the conversion event.
- You can also check your browser's DevTools Console to see if the
uetqarray has the conversion event pushed to it after submission.
内容的提问来源于stack exchange,提问作者TM88

