Help With Google Analytics E-commerce Tracking Code

#wixWindow #trackEvents #googleAnalytics #wixCode #ecommerce

Hey guys,

So, I have a custom coded store and I’m sending data to Google Analytics E-commerce with wix-window track event.

I’m doing so by creating a data layer and then having Google Tag Manager pick up the data from the Data layer using Data Layer Variables and finally pushing it to Google Analytics with GTM’s Custom HTML Tag.

The ’ ecommerce:addTransaction ’ is working flawlessly but I’m having trouble sending over product data using ’ ecommerce:addItem

Resources for the Google Analytics code: Ecommerce Measurement  |  Analytics for Web (analytics.js)  |  Google for Developers

So my product data is in a repeater and I using the following code to push the data into an array.

var array = [];

async function create() {
 await $w("#repeater1").forEachItem( ($item, itemData, index) => {
 let product = {
            id: $w("#reference").text,
            name: $item("#itemName").text,
            quantity: $item("#quantity").text,
            price: $item("#price").text
            };
            array.push(product);
        });
        custom();
}

However after the event is fired using the below code.

async function custom() {
    wixWindow.trackEvent("CustomEvent", {
        event: 'Custom Purchase',
        price: $w("#total").text,
        id: $w("#reference").text,
        affiliation: $w("#name").text,
        contents: array //problem here
        });
}

My transaction data is not flowing through because Google Analytics expects a JSON payload and not an array. See the console log from Google Analytics Debugger below.

See, in the line for ga(“ecommerce:addItem”, [{id:…
there is an array which I believe is the reason my product data does not get sent.

Apart from that transactions are flowing perfectly.

I tried converting the array into a string and then replacing the ‘[’ with nothing but if I do that it gives me a ‘Object Object’ in the Data Layer.

UPDATE

I tried to test it by hard coding an item data into the code like this:

async function custom() {
    wixWindow.trackEvent("CustomEvent", {
        event: 'Custom Purchase',
        price: $w("#total").text,
        id: $w("#reference").text,
        affiliation: $w("#name").text,
        contents: {
            id: '18',
            name: 'Bananas',
            quantity: '1',
            price: '250'
        }
        });
}

And its working


See no array (along with square brackets)

And I can see the log for the item hitType in Google Analytics Debugger

Confirmed in GA Dashboard

My Conclusion:

Google Analytics does not accept an array which the wixWindow Purchase Event is sending.

Bump.

Still not solved.