Created
June 2, 2016 16:40
-
-
Save FlorianTopf/f6f35a1cc830758041f9f8ef8dece16f to your computer and use it in GitHub Desktop.
Revisions
-
FlorianTopf created this gist
Jun 2, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,94 @@ ;(function () { 'use strict'; var app = this; var className = 'OrderProcessingAnalytics'; // saving the start time var orderProcessingStartTime = 0; var orderProcessingStopTime = 0; var measuringInProgress = false; var currentSellerId = null; var currentOrderAmount = 0; var currentTargetStatus = null; var currentOriginStatus = 'pending'; function getCurrentSellerFromDataLayer() { var sellerId = null; for (var item in window.dataLayer) { if (item.hasOwnProperty('sellerId')) { sellerId = item.sellerId; break; } } return sellerId === null ? null : parseInt(sellerId, 0); } function OrderProcessingAnalytics() { this.initialize() } app.services[className] = OrderProcessingAnalytics; OrderProcessingAnalytics.prototype = { initialize: function () { currentSellerId = getCurrentSellerFromDataLayer(); }, startMeasuringDelta: function () { var self = this; self.resetTemporaryData(); orderProcessingStartTime = Date.now(); measuringInProgress = true; }, stopMeasuringDelta: function () { orderProcessingStopTime = Date.now(); measuringInProgress = false; return orderProcessingStopTime - orderProcessingStartTime; }, resetTemporaryData: function () { orderProcessingStartTime = 0; orderProcessingStopTime = 0; currentOrderAmount = 0; currentTargetStatus = null; }, stopMeasuringDeltaAndPushData: function () { var self = this; if (false === measuringInProgress) { return; } var timeDifference = self.stopMeasuringDelta(); if (window.hasOwnProperty('dataLayer')) { window.dataLayer.push({ event: 'orderProcessing', startTime: moment(orderProcessingStartTime).format(), stopTime: moment(orderProcessingStopTime).format(), delta: timeDifference, sellerId: currentSellerId, originStatus: currentOriginStatus, targetStatus: currentTargetStatus, orderAmount: currentOrderAmount }); } }, setTargetStatus: function (targetStatus) { currentTargetStatus = targetStatus; }, setOrderAmount: function (orderAmount) { currentOrderAmount = orderAmount; } } }).call(window.App);