Dear Team WiX,
On more and more occasions it is becoming necessary to track purchases, especially for analytics so I thought I’d put this through as a feature request.
Essentially, we need a way to parse through a custom variable we can track to a user’s cart so that when checkout occurs, we can take action. Ideally, this custom value would then feed through to wix-stores-backend > events > onCartCompleted() or similar, so we can pull the custom variable when a purchase has been made and do stuff with it.
The way we’re doing it now is by creating and applying coupons on checkout, this flow is essentially what we need as it allows us to push through a custom value we can track when a purchase is completed, however using coupons forces us to 1. create a bunch of custom coupons and 2. apply discounts which is not ideal in every situation.
My thoughts - applying variable on checkout page:
import { cart } from 'wix-stores';
const trackingVariable= "someTrackingVariable";
cart.applyTrackingVariable(trackingVariable)
Fetching Variable:
// Place this code in the events.js file
// of your site's Backend section.
export function wixStores_onCartCompleted(event) {
let total = event.totals.total;
}
/* Full event object:
*
* {
* "cartId": "6d158831-1510-44ae-a420-1483a4200852",
* "completedTime": "2019-02-27T12:08:16.160Z",
* "buyerInfo": {
* "id": "091a8443-ab85-480c-918b-777156358dfc",
* "firstName": "John",
* "lastName": "Doe"
* "email": "john.doe@somedomain.com",
* "phone": "5555555555",
* "identityType": "CONTACT"
* },
* "weightUnit": "LB",
* "buyerNote": "This is a note from the buyer.",
* "billingAddress": {
* "firstName": "John",
* "lastName": "Doe"
* "email": "john.doe@somedomain.com",
* "phone": "5555555555",
* "address": "235 W 23rd St, New York, NY 10011, USA"
* },
* "currency": {
* "currency": "USD",
* "symbol": "$"
* },
* trackingVariable: “someTrackingVariable”,
* "appliedCoupon": {
* "couponId": "e81e9c48-f954-4044-ba64-ccfe5c103c8f",
* "name": "Summer Sale",
* "code": "SummerSale",
* "discountValue": "$10.00",
* "couponType": "MoneyOff"
* },
* "totals": {
* "subtotal": 250,
* "discount": 10,
* "total": 240,
* "quantity": 2
* },
* "shippingInfo": {
* "pickupDetails": {
* "firstName": "John",
* "lastName": "Doe"
* "email": "john.doe@somedomain.com",
* "phone": "5555555555",
* "address": "235 W 23rd St, New York, NY 10011, USA"
* },
* }
* }
*
*/
Side note - If we can have something similar for WiX Paid Plans that would be awesome!
Thank you for taking a look!
Tiaan