function DataLayerWrapper() { this.gtag = window.gtag || function() { window.dataLayer.push(arguments); }; // Kutsutaan session_start-metodia konstruktoriin //this.sessionStart(); } // Metodi: jutun_tilaus_alku DataLayerWrapper.prototype.jutunTilaus = function() { const sessionStartData = { event: "jutun_tilaus_alku" }; this.gtag('event', 'jutun_tilaus_alku', sessionStartData); console.log(sessionStartData); }; // Metodi: jutun_tilaus_maksu DataLayerWrapper.prototype.jutunTilausMaksu = function( itemDetails) { this.gtag('event', 'jutun_tilaus_maksu', itemDetails); console.log(itemDetails); }; // Metodi: begin_order DataLayerWrapper.prototype.beginOrder = function() { const sessionStartData = { event: "begin_order" }; this.gtag('event', 'begin_order', sessionStartData); console.log(sessionStartData); }; // Metodi: sessionStart DataLayerWrapper.prototype.sessionStart = function() { const sessionStartData = { event: "session_start", currency: "EUR" }; this.gtag('event', 'session_start', sessionStartData); console.log(sessionStartData); }; // Metodi: viewItem DataLayerWrapper.prototype.viewItem = function(itemDetails) { const viewItemData = { currency: "EUR", items: [itemDetails] }; this.gtag('event', 'view_item', viewItemData); console.log(viewItemData); }; // Metodi: selectItem DataLayerWrapper.prototype.selectItem = function(itemDetails) { const selectItemData = { currency: "EUR", items: [itemDetails] }; this.gtag('event', 'select_item', selectItemData); console.log(selectItemData); }; // Metodi: addToCart DataLayerWrapper.prototype.addToCart = function(itemDetails) { const addToCartData = { currency: "EUR", items: [itemDetails] }; this.gtag('event', 'add_to_cart', addToCartData); console.log(addToCartData); }; // Metodi: addShippingInfo DataLayerWrapper.prototype.addShippingInfo = function(shippingDetails, itemDetails) { const addShippingInfoData = { currency: "EUR", value: shippingDetails.value, coupon: shippingDetails.coupon, shipping_tier: shippingDetails.shipping_tier, items: [itemDetails] }; this.gtag('event', 'add_shipping_info', addShippingInfoData); console.log(addShippingInfoData); }; // Metodi: begin_checkout DataLayerWrapper.prototype.begin_checkout = function(itemDetails) { const addBeginCheckoutInfoData = { items: [itemDetails] }; this.gtag('event', 'begin_checkout', addBeginCheckoutInfoData); console.log(addBeginCheckoutInfoData); }; // Metodi: add_payment_info DataLayerWrapper.prototype.add_payment_info = function(itemDetails) { const addPaymentInfoData = { items: [itemDetails] }; this.gtag('event', 'add_payment_info', addPaymentInfoData); console.log(addPaymentInfoData); }; // Metodi: purchase DataLayerWrapper.prototype.purchase = function(purchaseDetails, itemDetails) { const purchaseData = { currency: "EUR", transaction_id: purchaseDetails.transaction_id, value: purchaseDetails.value, tax: purchaseDetails.tax, shipping: purchaseDetails.shipping, coupon: purchaseDetails.coupon, items: [itemDetails] }; this.gtag('event', 'purchase', purchaseData); console.log(purchaseData); };