Google Tag Tracking with trackEvent & CustomEvent Giving Unexpected Token Error

Hi,

I have been attempting to add Google Tag Manager Event tracking to one of the buttons our website.

We set up a new test page containing a button where we were going to test the tracking script from the following article:

https://support.wix.com/en/article/corvid-tutorial-sending-tracking-and-analytics-events

Upon loading the page preview though we received the attached JS error message:

We have removed the tracking script and saved the page (we haven’t published it) and the error remains.

Our tracking script was:

import wixWindow from ‘wix-window’;
export function button14_click(event) {
wixWindow.trackEvent(“CustomEvent”, {
“event”: “Test Button Clicked”,
“eventCategory”: “Test Button”,
“eventAction”: “click”,
“eventLabel”: “Test Button”
});
}

Has anyone had this issue before or does anyone know how to resolve this?

Any help would be greatly appreciated.

Many Thanks

The error is telling you where the problem is, on line 16 with the parentheses, which is the ‘)’ on that line.

You simply need to make sure that you have matching pairs of curly brackets and parentheses on your code, so simple terms you need equal pairs of open { and ( along with close } and ).

So the code with the page onReady function added would be like this with the existing tutorial code shown below too.

Added the page onReady function.

import wixWindow from 'wix-window';

$w.onReady(function () {

export function downloadButton_click(event) {
wixWindow.trackEvent("CustomEvent", {
"event": "Document Download",
"eventCategory": "Downloads",
"eventAction": "Download",
"eventLabel": $w('#dataset1').getCurrentItem().title
});
});
}

// Six (6) of open (
// Three (3) of open {
// Six (6) of close )
// Three (3) of close }

Tutorial

import wixWindow from 'wix-window';

export function downloadButton_click(event) {
wixWindow.trackEvent("CustomEvent", {
"event": "Document Download",
"eventCategory": "Downloads",
"eventAction": "Download",
"eventLabel": $w('#dataset1').getCurrentItem().title
});
}

// Four (4) of open (
// Two (2) of open {
// Four (4) of close )
// Two (2) of close }

Hi givemeawhisky,

Thank you for getting back to me on this query.

I have followed your sample and have used the following code:

import wixWindow from 'wix-window';

$w.onReady(function () {
 //TODO: write your page related code here...

});

export function button14_click(event) {
 //Add your code for this event here: 
    wixWindow.trackEvent("CustomEvent", {
 "event": "Test Button Clicked",
 "eventCategory": "Test Button",
 "eventAction": "click",
 "eventLabel": "Test Button"
    });
}

// open ( - 4
// close ) - 4
// open { - 3
// close } - 3

However we are still getting the same error in the masterPage.js file.

I have checked the ‘i805u.js’ file mentioned in the console which reads as follows:

(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.i805u = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
"use strict";

Object.defineProperty(exports, "__esModule", {
	value: true
});
exports.button14_click = button14_click;

var _wixWindow = require("wix-window");

var _wixWindow2 = _interopRequireDefault(_wixWindow);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

$w.onReady(function () {
	//TODO: write your page related code here...

}); // For full API documentation, including code examples, visit https://wix.to/94BuAAs

function button14_click(event) {
	//Add your code for this event here: 
	_wixWindow2.default.trackEvent("CustomEvent", {
		"event": "Test Button Clicked",
		"eventCategory": "Test Button",
		"eventAction": "click",
		"eventLabel": "Test Button"
	});
}

},{"wix-window":undefined}]},{},[1])(1)
});
//# sourceMappingURL=https://c668a78b-032a-43fe-b0bb-2c542d6b9083.dev.wix-code.com/pages/i805u.js.map?empty-if-missing=true&exclude=wix-&module-name=i805u&viewMode=preview&instance=wixcode-dev.76b63554b583464fbe8ca1ca9582332093a2b948.eyJpbnN0YW5jZUlkIjoiYzY2OGE3OGItMDMyYS00M2ZlLWIwYmItMmM1NDJkNmI5MDgzIiwiY29ycmVsYXRpb25JZCI6IjI2ZThjOGUxLWE5NzktNGYzNS04NmNmLTI4NzQ5MmRiMmI1YiIsInNlc3Npb25VSWQiOiJkYmY5YmJhYS1kMmM1LTQ5MDctYjVlNy01NzA4YTBjZjk2YWMiLCJpc1RlbXBsYXRlIjpmYWxzZSwic2lnbkRhdGUiOjE1NzI5NDg0MDM2MDYsInNpdGVNZW1iZXJJZCI6ImRiZjliYmFhLWQyYzUtNDkwNy1iNWU3LTU3MDhhMGNmOTZhYyIsInVpZCI6ImRiZjliYmFhLWQyYzUtNDkwNy1iNWU3LTU3MDhhMGNmOTZhYyIsImFwcERlZklkIjoiQ2xvdWRTaXRlRXh0ZW5zaW9uIiwiaXNBZG1pbiI6ZmFsc2UsIm1ldGFTaXRlSWQiOiIyMzBhNTFiNC1hNDYwLTQxN2MtYjVjZS1lMmUzZDI0OTRjZDAiLCJjYWNoZSI6bnVsbCwiZXhwaXJhdGlvbkRhdGUiOiIyMDE5LTExLTA1VDE0OjA2OjQzLjYwNloiLCJzaXRlT3duZXJJZCI6IjM2MjQ2MmUyLTA1YjMtNGQzZS04MzBjLTQ1MjdlNTk2YjM0NCJ9&gridAppId=a9c19fb6-903b-44f4-a9ec-520840a6f9b1&cacheKiller=1572949734818

But I can’t see any obvious issues with this code.

Additionally, the same ‘masterPage.js’ error message is displayed on every page. Even pages where the ‘i805u.js’ and our tracking code is not loaded in.