#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: https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce
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.
![](https://static.wixstatic.com/media/a27d24_f00cc1a206fd44348413bb7e32599a5b~mv2.png/v1/fill/w_980,h_155,al_c,q_85,usm_0.66_1.00_0.01,enc_auto/a27d24_f00cc1a206fd44348413bb7e32599a5b~mv2.png)
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.
![](https://static.wixstatic.com/media/a27d24_a37ca2ca5714470e8e681d44413cbaa0~mv2_d_1200_1920_s_2.jpg/v1/fill/w_980,h_1568,al_c,q_85,usm_0.66_1.00_0.01,enc_auto/a27d24_a37ca2ca5714470e8e681d44413cbaa0~mv2_d_1200_1920_s_2.jpg)
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
![](https://static.wixstatic.com/media/a27d24_6f99377fe648458d8d7b34928bb227a4~mv2.png/v1/fill/w_944,h_116,al_c,q_85,enc_auto/a27d24_6f99377fe648458d8d7b34928bb227a4~mv2.png)
See no array (along with square brackets)
And I can see the log for the item hitType in Google Analytics Debugger
![](https://static.wixstatic.com/media/a27d24_692154683fe84930a6779bc6de0ba8d2~mv2.png/v1/fill/w_386,h_266,al_c,q_85,enc_auto/a27d24_692154683fe84930a6779bc6de0ba8d2~mv2.png)
Confirmed in GA Dashboard
![](https://static.wixstatic.com/media/a27d24_ddf1c5cf6b1e45c5bf935b56064b4f93~mv2_d_1200_1920_s_2.jpg/v1/fill/w_980,h_1568,al_c,q_85,usm_0.66_1.00_0.01,enc_auto/a27d24_ddf1c5cf6b1e45c5bf935b56064b4f93~mv2_d_1200_1920_s_2.jpg)
My Conclusion:
Google Analytics does not accept an array which the wixWindow Purchase Event is sending.
Bump.
Still not solved.