function CourseGa(bookingForm, option) { this.bookingForm = bookingForm; this.option = option; this.data = {}; // this.onClickSubmit = this.onClickSubmit.bind(this); this.onFormSubmit = this.onFormSubmit.bind(this); // document.getElementById('btn-submit').addEventListener('click', this.onClickSubmit); document.getElementById(this.bookingForm.id).addEventListener('submit', this.onFormSubmit); } /* CourseGa.prototype.onClickSubmit = function (evt) { // this.data = this.setGaData(); window.dataLayer = window.dataLayer || []; window.dataLayer.push({ ecommerce: null }); window.dataLayer.push({ event: "purchase", // Event name // ecommerce: this.data, ecommerce: this.setGaData() }); } */ CourseGa.prototype.onFormSubmit = function (evt) { window.dataLayer = window.dataLayer || []; window.dataLayer.push({ ecommerce: null }); window.dataLayer.push({ event: "purchase", // Event name // ecommerce: this.data, ecommerce: this.setGaData() }); } CourseGa.prototype.setGaData = function () { this.data = { transaction_id: courseTransactionId(), // Randomized unique transaction ID value: this.bookingForm.price["total"], // Total value including all deltakere currency: this.option.currency, // Monetary currency items: [ { item_name: courseType(), // Course name coupon: courseVoucher(), // Voucher/Coupon string currency: this.option.currency, // Monetary currency discount: this.bookingForm.price["coupon"], // Monetary value of discount item_brand: this.option.brand, // Static price: this.bookingForm.price["person"], // Value of 1 item/course (1 deltaker) quantity: this.bookingForm.participantCount() // Numerical amount of deltakere }, ] }; return this.data; }