Wix
Add elNudge to your Wix site using Velo custom code — covers script injection, route change tracking, and Wix Stores cart events.
elNudge can be added to Wix sites via Velo by Wix (formerly Wix Code). Velo lets you inject custom JavaScript into your site's <head> and write page-level code that reacts to navigation and store events.
Before you start: Velo must be enabled on your site. Go to Settings → Developer Tools → Enable Velo by Wix if you have not done so already.
1. Add the script snippet to your site's head
Wix does not expose a raw <head> file, but you can inject code through Settings → Custom Code:
- In the Wix Editor, open Settings (the gear icon in the left sidebar).
- Select Custom Code → Head.
- Click + Add Custom Code.
- Paste the elNudge loader snippet:
<script> (function(w,d,s,k){ w.__eln=w.__eln||function(){(w.__eln.q=w.__eln.q||[]).push(arguments)}; var t=d.createElement(s);t.async=1; t.src='https://cdn.elnudge.com/v1/sdk.js'; t.setAttribute('data-site-key',k); d.head.appendChild(t); })(window,document,'script','sk_live_YOUR_SITE_KEY'); </script> - Set Add Code to Pages to All Pages.
- Set Place Code in to Head.
- Click Apply and then Publish your site.
Replace sk_live_YOUR_SITE_KEY with the key from app.elnudge.com → your site → Install.
2. Track route changes with Velo page code
Wix uses its own client-side router. The standard pushState/replaceState events that elNudge auto-detects on other platforms are not always dispatched in Wix's environment. To ensure page views are tracked accurately, fire a manual signal on each page using Velo's $w.onReady callback.
Open the Page Code panel (bottom of the Velo editor) on any page you want to track, and add:
// page-code.js (repeat on each page, or use site-wide masterPage.js)
$w.onReady(function () {
if (typeof window.__eln === 'function') {
// elNudge auto-fires PAGE_VIEW on load; this call is only needed
// if you want to pass additional page context.
window.__eln('track', 'PAGE_VIEW', {
page_title: document.title,
page_url: window.location.href,
});
}
});
For site-wide coverage, place this in masterPage.js (the Site tab in the Velo code panel) instead of individual page files.
Using Wix's beforeNavigate for route changes
If your site has multiple dynamic pages (e.g., a blog or product catalog), you can hook into Wix's navigation lifecycle to fire events before the visitor leaves a page:
// masterPage.js
import wixLocation from 'wix-location';
$w.onReady(function () {
// Track the initial page view
if (typeof window.__eln === 'function') {
window.__eln('track', 'PAGE_VIEW', {
page_url: wixLocation.url,
});
}
});
Note: Wix's sandbox restricts direct access to
window.historyand some native browser APIs. Route-change auto-detection by elNudge may not fire on every navigation. The$w.onReadyapproach above is the most reliable method for Wix sites.
3. Fire cart events with Wix Stores
If you use Wix Stores, you can track cart additions using the Wix Stores Events API. Add the following to masterPage.js:
// masterPage.js
import { cart } from 'wix-stores-frontend';
$w.onReady(function () {
// Listen for items added to the cart
cart.onChange((updatedCart) => {
const lastAdded = updatedCart.lineItems[updatedCart.lineItems.length - 1];
if (lastAdded && typeof window.__eln === 'function') {
window.__eln('track', 'CART_ADD', {
product_id: lastAdded.productId,
product_name: lastAdded.name,
variant: lastAdded.options ? Object.values(lastAdded.options).join(', ') : '',
price: String(lastAdded.price),
currency: updatedCart.currency,
quantity: lastAdded.quantity,
});
}
});
});
Limitation:
cart.onChangefires on any cart mutation (additions, removals, quantity changes). If you need to distinguish between additions and removals, compare the cart state before and after the event using a local variable.
For the purchase event, add it to your Thank You Page code:
// Thank You page — Page Code
$w.onReady(function () {
// Wix Stores passes order data via the URL or Wix's order confirmation APIs
// Use the wix-pay or wix-stores backend to retrieve the order total
if (typeof window.__eln === 'function') {
window.__eln('track', 'PURCHASE', {
order_value: '0.00', // replace with actual order total from your backend
currency: 'USD', // replace with actual currency
item_count: 1, // replace with actual item count
});
}
});
Because Wix Stores does not expose the full order object in frontend page code at the time of writing, you may need to use a Wix backend function (HTTP function or data hook) to retrieve the order and pass it to the page via a wix-window message or a query parameter.
Sandbox limitations
Wix runs all custom code in a sandboxed iframe environment. The following limitations apply:
| Feature | Status |
|---|---|
<head> custom code injection | Supported via Settings → Custom Code |
pushState / replaceState auto-detection | Unreliable — use $w.onReady manually |
Direct document / window manipulation | Partially restricted |
wix-stores-frontend cart events | Supported |
| Server-side hooks | Not available — all events are JS-only |
Quiet zones
To suppress nudges on specific pages (e.g., your blog, legal pages), add the data-quiet-zones attribute to the custom code snippet in Settings → Custom Code:
<script>
(function(w,d,s,k){
w.__eln=w.__eln||function(){(w.__eln.q=w.__eln.q||[]).push(arguments)};
var t=d.createElement(s);t.async=1;
t.src='https://cdn.elnudge.com/v1/sdk.js';
t.setAttribute('data-site-key',k);
t.setAttribute('data-quiet-zones','/blog,/blog/*,/privacy-policy,/contact');
d.head.appendChild(t);
})(window,document,'script','sk_live_YOUR_SITE_KEY');
</script>
You can also set quiet zones in app.elnudge.com → your site → Engagement Rules → Quiet Zones.
Verify the install
- Publish your site and open it in a browser.
- Open the browser console and run:
typeof window.__eln === 'function' // should return true - Check the Live view in app.elnudge.com — your session should appear within seconds of loading any page.
- If you enabled Wix Stores cart events, add a product to your cart and watch for an elNudge
CART_ADDevent in the console (adddata-debug="true"to the script tag temporarily to enable verbose logging).