/* analytis_sdk.js Author: StackStudio Website: DISM / SDK Date: 09/11/2018 */ /* GLOBAL VARIABLES */ var debug = false; if(("0"==true)||("0"==="true")||("0"=="1")) { debug = true; } /* VALIDATORS */ var brands = ["NR", "CH", "PR", "JPG", "QD", "PEN", "AB", "SHK", "CDG"]; var isoCountries = ['WW','INT','GLOBAL','AF','AX','AL','DZ','AS','AD','AO','AI','AQ','AG','AR','AM','AW','AU','AT','AZ','BS','BH','BD','BB','BY','BE','BZ','BJ','BM','BT','BO','BA','BW','BV','BR','IO','BN','BG','BF','BI','KH','CM','CA','CV','KY','CF','TD','CL','CN','CX','CC','CO','KM','CG','CD','CK','CR','CI','HR','CU','CY','CZ','DK','DJ','DM','DO','EC','EG','SV','GQ','ER','EE','ET','FK','FO','FJ','FI','FR','GF','PF','TF','GA','GM','GE','DE','GH','GI','GR','GL','GD','GP','GU','GT','GG','GN','GW','GY','HT','HM','VA','HN','HK','HU','IS','IN','ID','IR','IQ','IE','IM','IL','IT','JM','JP','JE','JO','KZ','KE','KI','KR','KW','KG','LA','LV','LB','LS','LR','LY','LI','LT','LU','MO','MK','MG','MW','MY','MV','ML','MT','MH','MQ','MR','MU','YT','MX','FM','MD','MC','MN','ME','MS','MA','MZ','MM','NA','NR','NP','NL','AN','NC','NZ','NI','NE','NG','NU','NF','MP','NO','OM','PK','PW','PS','PA','PG','PY','PE','PH','PN','PL','PT','PR','QA','RE','RO','RU','RW','BL','SH','KN','LC','MF','PM','VC','WS','SM','ST','SA','SN','RS','SC','SL','SG','SK','SI','SB','SO','ZA','GS','ES','LK','SD','SR','SJ','SZ','SE','CH','SY','TW','TJ','TZ','TH','TL','TG','TK','TO','TT','TN','TR','TM','TC','TV','UG','UA','AE','GB','US','UM','UY','UZ','VU','VE','VN','VG','VI','WF','EH','YE','ZM','ZW']; var isoLanguages = ['aa','ab','ae','af','ak','am','an','ar','as','av','ay','az','ba','be','bg','bh','bi','bm','bn','bo','br','bs','ca','ce','ch','co','cr','cs','cu','cv','cy','da','de','dv','dz','ee','el','en','eo','es','et','eu','fa','ff','fi','fj','fo','fr','fy','ga','gd','gl','gn','gu','gv','ha','he','hi','ho','hr','ht','hu','hy','hz','ia','id','ie','ig','ii','ik','io','is','it','iu','ja','jv','ka','kg','ki','kj','kk','kl','km','kn','ko','kr','ks','ku','kv','kw','ky','la','lb','lg','li','ln','lo','lt','lu','lv','mg','mh','mi','mk','ml','mn','mr','ms','mt','my','na','nb','nd','ne','ng','nl','nn','no','nr','nv','ny','oc','oj','om','or','os','pa','pi','pl','ps','pt','qu','rm','rn','ro','ru','rw','sa','sc','sd','se','sg','si','sk','sl','sm','sn','so','sq','sr','ss','st','su','sv','sw','ta','te','tg','th','ti','tk','tl','tn','to','tr','ts','tt','tw','ty','ug','uk','ur','uz','ve','vi','vo','wa','wo','xh','yi','yo','za','zh','zu']; var currencies = ["UNKNOWN", "AED", "AFN", "ALL", "AMD", "ANG", "AOA", "ARS", "AUD", "AWG", "AZN", "BAM", "BBD", "BDT", "BGN", "BHD", "BIF", "BMD", "BND", "BOB", "BOV", "BRL", "BSD", "BTN", "BWP", "BYR", "BZD", "CAD", "CDF", "CHE", "CHF", "CHW", "CLF", "CLP", "CNY", "COP", "COU", "CRC", "CUC", "CUP", "CVE", "CZK", "DJF", "DKK", "DOP", "DZD", "EGP", "ERN", "ETB", "EUR", "FJD", "FKP", "GBP", "GEL", "GHS", "GIP", "GMD", "GNF", "GTQ", "GYD", "HKD", "HNL", "HRK", "HTG", "HUF", "IDR", "ILS", "INR", "IQD", "IRR", "ISK", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KMF", "KPW", "KRW", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LTL", "LVL", "LYD", "MAD", "MDL", "MGA", "MKD", "MMK", "MNT", "MOP", "MRO", "MUR", "MVR", "MWK", "MXN", "MXV", "MYR", "MZN", "NAD", "NGN", "NIO", "NOK", "NPR", "NZD", "OMR", "PAB", "PEN", "PGK", "PHP", "PKR", "PLN", "PYG", "QAR", "RON", "RSD", "RUB", "RWF", "SAR", "SBD", "SCR", "SDG", "SEK", "SGD", "SHP", "SLL", "SOS", "SRD", "SSP", "STD", "SYP", "SZL", "THB", "TJS", "TMT", "TND", "TOP", "TRY", "TTD", "TWD", "TZS", "UAH", "UGX", "USD", "USN", "USS", "UYI", "UYU", "UZS", "VEF", "VND", "VUV", "WST", "XAF", "XAG", "XAU", "XBA", "XBB", "XBC", "XBD", "XCD", "XDR", "XFU", "XOF", "XPD", "XPF", "XPT", "XTS", "XXX", "YER", "ZAR", "ZMW"]; var pageTypes = ["404","home", "store", "search", "category", "pdp", "checkout", "transaction", "account", "other", "social","email"]; var environments = ["development", "staging", "production", "local"]; var genders = ["m","f","u"]; var constructorAnalytics = false; //This variable will become true once the constructor of the has been called once, this is used in order to guarantee this. /* END SCRIPT HEADER TOP BEFORE GTM TAG */ var trackManager = function() { // ********** Variables ********** //This variable is filled with every available data manager, such as Google Analytics Data Manager Object. available_data_manager_array = []; // ********** Constructor ********** // Constructor function call if(!constructorAnalytics) { init(); } // ********** Private Methods ********** // Constructor function that sets up every data_manager into available_data_manager_array. function init() { // Init the google analytics object. var g_analytics_data_manager = {}; g_analytics_data_manager.slug = "Google Analytics"; g_analytics_data_manager.object = g_analytics(); available_data_manager_array.push(g_analytics_data_manager); var valid_data = validate(); if((!valid_data.success)&&(debugMode())) { if(typeof valid_data.log != "undefined") { console.error(valid_data.log); } } constructorAnalytics = true; } function getParams(_func, _arguments) { // First match everything inside the function argument parens. var args = _func.toString().match(/function\s.*?\(([^)]*)\)/)[1]; // Split the arguments string into an array comma delimited. var indexParams = args.split(',').map(function(arg) { // Ensure no inline comments are parsed and trim the whitespace. return arg.replace(/\/\*.*\*\//, '').trim(); }).filter(function(arg) { // Ensure no undefined values are added. return arg; }); var args = new Array(_arguments.length); for(var i = 0; i < args.length; ++i) { args[""+indexParams[i]] = _arguments[i]; } return args; } function checkVariables(_params){ var response = {"success":true,"message":[]}; for (var param in _params) { if (_params.hasOwnProperty(param)) { switch(param){ case "brand": var validResponse = validateBrand(_params[param]); if(!validResponse.success) { response.success = false; response.message.push("Error: "+param+" => "+validResponse.message); } break; case "countryCode": var validResponse = validateISOCountry(_params[param]); if(!validResponse.success) { response.success = false; response.message.push("Error: "+param+" => "+validResponse.message); } break; case "languageCode": var validResponse = validateISOLanguage(_params[param]); if(!validResponse.success) { response.success = false; response.message.push("Error: "+param+" => "+validResponse.message); } break; case "currencyCode": var validResponse = validateCurrency(_params[param]); if(!validResponse.success) { response.success = false; response.message.push("Error: "+param+" => "+validResponse.message); } break; case "environmentName": var validResponse = validateEnvironment(_params[param]); if(!validResponse.success) { response.success = false; response.message.push("Error: "+param+" => "+validResponse.message); } break; // case "type": // var validResponse = validatePageType(_params[param]); // if(!validResponse.success) // { // response.success = false; // response.message.push("Error: "+param+" => "+validResponse.message); // } // break; case "gender": var validResponse = validateGender(_params[param]); if(!validResponse.success) { response.success = false; response.message.push("Error: "+param+" => "+validResponse.message); } break; } } } return response; } function validate(){ var data = dataLayer || window.dataLayer; var debugValidate = []; for(i in data){ for(var keyA in data[i]){ if(data[i].hasOwnProperty(keyA) && typeof data[i][keyA] === 'object'){ var response = checkVariables(data[i][keyA]); debugValidate.push(response); for(var keyB in data[i][keyA]){ if(data[i][keyA].hasOwnProperty(keyB) && typeof data[i][keyA][keyB] === 'object'){ var response = checkVariables(data[i][keyA][keyB]); debugValidate.push(response); } } } } } var responseObj = {"success": true, "log": []}; for(i in debugValidate){ if(!debugValidate[i].success){ responseObj.success = false; for(j in debugValidate[i].message){ responseObj.log.push(debugValidate[i].message[j]); } } } if(debugMode()) { return responseObj; }else{ return "Method not available."; } } function debugMode() { if((typeof debug != undefined)&&(debug)) { return true; }else{ return false; } } function getAnonymousInfo() { var _arrayAnonymous = []; //Get Anonymous ID from tag HEAD if(typeof bo != "undefined"){ if(bo.anonymousUserId != null && bo.anonymousUserSource != null){ if(typeof ciam != "undefined" && ciam.hasOwnProperty("syncAnonymousUserInfo")){ var anonymousUser = {id: bo.anonymousUserId, source: bo.anonymousUserSource}; _arrayAnonymous.push(anonymousUser); } } } //Get Anonymous Client ID if(typeof ga != "undefined"){ ga(function() { var clientId = ga.getAll()[0].get('clientId'); var anonymousUser = {id: clientId, source: "GoogleAnalytics"}; _arrayAnonymous.push(anonymousUser); }); } return _arrayAnonymous; } function apiResponse(_status,_message) { return {"success":_status,"message":_message}; } /* DATA VALIDATORS */ /* validateBrand validateGender validateEnvironment validateISOCountry validateISOLanguage validatePageType validateCurrency */ function validateBrand(_brand) { var response = {"success":true,"message":""}; if(typeof _brand !== 'undefined'){ if(_brand) { if(isString(_brand) && brands.includes(_brand.toUpperCase())) { // Value is valid. Is valid gender }else{ response.success = false; response.message = "Invalid input value: "+_brand; } }else{ response.success = false; response.message = "Value cannot be null"; } }else{ response.success = false; response.message = "Input value is undefined"; } return response; } function validateGender(_gender) { var response = {"success":true,"message":""}; if(typeof _gender !== 'undefined'){ if(_gender) { if(isString(_gender) && genders.includes(_gender.toLowerCase())) { // Value is valid. Is valid gender }else{ response.success = false; response.message = "Invalid input value: "+_gender; } }else{ response.success = false; response.message = "Value cannot be null"; } }else{ response.success = false; response.message = "Input value is undefined"; } return response; } function validateEnvironment(_environmentName) { var response = {"success":true,"message":""}; if(typeof _environmentName !== 'undefined'){ if(_environmentName) { if(isString(_environmentName) && environments.includes(_environmentName)) { // Value is valid. Is valid pageCategory }else{ response.success = false; response.message = "Invalid input value: "+_environmentName; } }else{ if(_environmentName!=null) { response.success = false; response.message = "Invalid input value: "+_environmentName; } } }else{ response.success = false; response.message = "Input value is undefined"; } return response; } function validatePageType(_pageType) { var response = {"success":true,"message":""}; if(typeof _pageType !== 'undefined'){ if(_pageType) { if(isString(_pageType) && pageTypes.includes(_pageType)) { // Value is valid. Is valid pageCategory }else{ response.success = false; response.message = "Invalid input value: "+_pageType; } }else{ if(_pageType!=null) { response.success = false; response.message = "Invalid input value: "+_pageType; } } }else{ response.success = false; response.message = "Input value is undefined"; } return response; } function validateCurrency(_currencyCode){ var response = {"success":true,"message":""}; if(typeof _currencyCode !== 'undefined'){ if(_currencyCode) { if(isString(_currencyCode) && currencies.includes(_currencyCode.toUpperCase())) { // Value is valid. Is valid ISO Language }else{ response.success = false; response.message = "Invalid input value: "+_currencyCode; } }else{ if(_currencyCode != null) { response.success = false; response.message = "Invalid input value: "+_currencyCode; } } }else{ response.success = false; response.message = "Input value is undefined"; } return response; } function validateISOLanguage(_ISOLanguage){ var response = {"success":true,"message":""}; if(typeof _ISOLanguage !== 'undefined'){ if(_ISOLanguage) { if(isString(_ISOLanguage) && isoLanguages.includes(_ISOLanguage.toLowerCase())) { // Value is valid. Is valid ISO Language }else{ response.success = false; response.message = "Invalid input value: "+_ISOLanguage; } }else{ if(_ISOLanguage != null) { response.success = false; response.message = "Invalid input value: "+_ISOLanguage; } } }else{ response.success = false; response.message = "Input value is undefined"; } return response; } function validateISOCountry(_ISOCountry){ var response = {"success":true,"message":""}; if(typeof _ISOCountry !== 'undefined'){ if(_ISOCountry) { if(isString(_ISOCountry) && isoCountries.includes(_ISOCountry.toUpperCase())) { // Value is valid. Is valid ISO Country }else{ response.success = false; response.message = "Invalid input value: "+_ISOCountry; } }else{ if(_ISOCountry != null) { response.success = false; response.message = "Invalid input value: "+_ISOCountry; } } }else{ response.success = false; response.message = "Input value is undefined"; } return response; } function isString(_string){ return typeof _string === 'string' || _string instanceof String; } function isBoolean(_boolean){ return typeof _boolean === typeof true || _boolean instanceof Boolean; } function isPromotion(_promotion) { if(_promotion.hasOwnProperty('id') && _promotion.hasOwnProperty('name') && _promotion.hasOwnProperty('creative') && _promotion.hasOwnProperty('position')){ return true; }else{ return false; } } function isProductImpression(_product) { if(_product.hasOwnProperty('name') && _product.hasOwnProperty('id') && _product.hasOwnProperty('price') && _product.hasOwnProperty('brand') && _product.hasOwnProperty('category') && _product.hasOwnProperty('stock')) { return true; }else{ return false; } } function isProduct(_product, method) { if(_product.hasOwnProperty('name') && _product.hasOwnProperty('id') && _product.hasOwnProperty('price') && _product.hasOwnProperty('brand') && _product.hasOwnProperty('category') && _product.hasOwnProperty('stock')) { if(typeof method != "undefined"){ if((method == 'addToCart' || method == 'removeFromCart' || method == 'checkout' || method == 'transaction') && _product.hasOwnProperty('quantity')){ return true; }else if(method == 'productClick' || method == 'productDetail'){ return true; }else{ return false; } }else{ return false; } }else{ return false; } } function isActionField(_actionField, method) { if(typeof method != "undefined"){ if(method == "productDetail" && _actionField.hasOwnProperty('list')){ return true; }else if(method == "checkout" && _actionField.hasOwnProperty('step')){ return true; }else if(method == "transaction" && _actionField.hasOwnProperty('id') && _actionField.hasOwnProperty('revenue') && _actionField.hasOwnProperty('tax')){ return true; }else if(method == "productClick"){ return true; }else{ return false; } }else{ return false; } } // ********** Public Methods ********** function loginRegistrationModalOpen() { var response = {}; // Call the function through available_data_manager_array objects. available_data_manager_array.forEach(function(element) { if (typeof element.object.loginRegistrationModalOpen == 'function') { response = element.object.loginRegistrationModalOpen(); } }); return response; } function loginSuccess() { var response = {}; // Call the function through available_data_manager_array objects. available_data_manager_array.forEach(function(element) { if (typeof element.object.loginSuccess == 'function') { response = element.object.loginSuccess(); } }); return response; } function registrationSuccess() { var response = {}; // Call the function through available_data_manager_array objects. available_data_manager_array.forEach(function(element) { if (typeof element.object.registrationSuccess == 'function') { response = element.object.registrationSuccess(); } }); return response; } function subscriptionModalOpen() { var response = {}; // Call the function through available_data_manager_array objects. available_data_manager_array.forEach(function(element) { if (typeof element.object.subscriptionModalOpen == 'function') { response = element.object.subscriptionModalOpen(); } }); return response; } function subscriptionSuccess() { var response = {}; // Call the function through available_data_manager_array objects. available_data_manager_array.forEach(function(element) { if (typeof element.object.subscriptionSuccess == 'function') { response = element.object.subscriptionSuccess(); } }); return response; } function contactFormOpen() { var response = {}; // Call the function through available_data_manager_array objects. available_data_manager_array.forEach(function(element) { if (typeof element.object.contactFormOpen == 'function') { response = element.object.contactFormOpen(); } }); return response; } function contactFormSubmission() { var response = {}; // Call the function through available_data_manager_array objects. available_data_manager_array.forEach(function(element) { if (typeof element.object.contactFormSubmission == 'function') { response = element.object.contactFormSubmission(); } }); return response; } function push(_parameters) { var response = {}; // Call the function through available_data_manager_array objects. available_data_manager_array.forEach(function(element) { if (typeof element.object.push == 'function') { response = element.object.push(_parameters); } }); return response; } function promotionClick(_promotion) { var response = {}; // Call the function through available_data_manager_array objects. available_data_manager_array.forEach(function(element) { if (typeof element.object.promotionClick == 'function') { response = element.object.promotionClick(_promotion); } }); return response; } function promotionImpression(_promotion) { var response = {}; // Call the function through available_data_manager_array objects. available_data_manager_array.forEach(function(element) { if (typeof element.object.promotionImpression == 'function') { response = element.object.promotionImpression(_promotion); } }); return response; } function promotionsImpression(_parameters) { var response = {}; // Call the function through available_data_manager_array objects. available_data_manager_array.forEach(function(element) { if (typeof element.object.promotionsImpression == 'function') { response = element.object.promotionsImpression(_parameters); } }); return response; } function productImpression(_parameters) { var response = {}; // Call the function through available_data_manager_array objects. available_data_manager_array.forEach(function(element) { if (typeof element.object.productImpression == 'function') { response = element.object.productImpression(_parameters); } }); return response; } function productClick(_parameters) { var response = {}; // Call the function through available_data_manager_array objects. available_data_manager_array.forEach(function(element) { if (typeof element.object.productClick == 'function') { response = element.object.productClick(_parameters); } }); return response; } function pdpView(_parameters) { var response = {}; // Call the function through available_data_manager_array objects. available_data_manager_array.forEach(function(element) { if (typeof element.object.pdpView == 'function') { response = element.object.pdpView(_parameters); } }); return response; } function addToCart(_parameters) { var response = {}; // Call the function through available_data_manager_array objects. available_data_manager_array.forEach(function(element) { if (typeof element.object.addToCart == 'function') { response = element.object.addToCart(_parameters); } }); return response; } function removeFromCart(_parameters) { var response = {}; // Call the function through available_data_manager_array objects. available_data_manager_array.forEach(function(element) { if (typeof element.object.removeFromCart == 'function') { response = element.object.removeFromCart(_parameters); } }); return response; } function checkout(_parameters) { var response = {}; // Call the function through available_data_manager_array objects. available_data_manager_array.forEach(function(element) { if (typeof element.object.checkout == 'function') { response = element.object.checkout(_parameters); } }); return response; } function transaction(_parameters) { var response = {}; // Call the function through available_data_manager_array objects. available_data_manager_array.forEach(function(element) { if (typeof element.object.transaction == 'function') { response = element.object.transaction(_parameters); } }); return response; } function storeLocatorLinkClick() { var response = {}; // Call the function through available_data_manager_array objects. available_data_manager_array.forEach(function(element) { if (typeof element.object.storeLocatorLinkClick == 'function') { response = element.object.storeLocatorLinkClick(); } }); return response; } function storeLocatorOpen() { var response = {}; // Call the function through available_data_manager_array objects. available_data_manager_array.forEach(function(element) { if (typeof element.object.storeLocatorOpen == 'function') { response = element.object.storeLocatorOpen(); } }); return response; } function storeLocatorClose() { var response = {}; // Call the function through available_data_manager_array objects. available_data_manager_array.forEach(function(element) { if (typeof element.object.storeLocatorClose == 'function') { response = element.object.storeLocatorClose(); } }); return response; } // Public method declaration return { loginRegistrationModalOpen:function(){ return loginRegistrationModalOpen(); }, loginSuccess:function(){ return loginSuccess(); }, registrationSuccess:function(){ return registrationSuccess(); }, subscriptionModalOpen:function(){ return subscriptionModalOpen(); }, subscriptionSuccess:function(){ return subscriptionSuccess(); }, contactFormOpen:function(){ return contactFormOpen(); }, contactFormSubmission:function(){ return contactFormSubmission(); }, push:function(_parameters){ return push(_parameters); }, validate:function(){ return validate(); }, promotionImpression:function(_promotion){ return promotionImpression(_promotion); }, promotionsImpression:function(_parameters){ return promotionsImpression(_parameters); }, promotionClick:function(_promotion){ return promotionClick(_promotion); }, productImpression:function(_parameters){ return productImpression(_parameters); }, productClick:function(_parameters){ return productClick(_parameters); }, pdpView:function(_parameters){ return pdpView(_parameters); }, addToCart:function(_parameters){ return addToCart(_parameters); }, removeFromCart:function(_parameters){ return removeFromCart(_parameters); }, checkout:function(_parameters){ return checkout(_parameters); }, transaction:function(_parameters){ return transaction(_parameters); }, isPromotion:function(_promotion){ return isPromotion(_promotion); }, isProductImpression:function(_product){ return isProductImpression(_product); }, isProduct:function(_product, method){ return isProduct(_product, method); }, isActionField:function(_product, method){ return isActionField(_product, method); }, //STORE LOCATOR METHODS storeLocatorLink:function(){ return storeLocatorLink(); }, storeLocatorOpen:function(){ return storeLocatorOpen(); }, storeLocatorClose:function(){ return storeLocatorClose(); }, //FUNCTIONALITIES getAnonymousInfo:function(){ return getAnonymousInfo(); } } }; var g_analytics = function() { // ********** Variables ********** // ********** Constructor ********** // Constructor function call init(); // ********** Private Methods ********** // Constructor function that sets up every data_manager into available_data_manager_array. function init() { } // ********** Public Methods ********** // loginRegistrationModalOpen -- Whenever the user opens the login/registration modal, this interaction should trigger a site interaction event with all relevant data fields. function loginRegistrationModalOpen() { try{ dataLayer.push({ 'event':'loginRegistrationOpen' }); return {success:true,code:200,message:"loginRegistrationOpen successfully pushed"}; }catch(err) { return {success:false,code:500,message:err.message}; } } // loginSuccess -- Whenever the user opens the login/registration modal, this interaction should trigger a site interaction event with all relevant data fields. function loginSuccess() { try{ dataLayer.push({ 'event':'loginSuccess' }); return {success:true,code:200,message:"loginSuccess successfully pushed"}; }catch(err) { return {success:false,code:500,message:err.message}; } } // registrationSuccess -- When the user is registered successfully, this interaction should trigger a site interaction event with all relevant data fields. function registrationSuccess() { try{ dataLayer.push({ 'event':'registrationSuccess' }); return {success:true,code:200,message:"registrationSuccess successfully pushed"}; }catch(err) { return {success:false,code:500,message:err.message}; } } // subscriptionModalOpen -- Whenever the user opens the newsletter signup modal, this interaction should trigger a site interaction event with all relevant data fields. function subscriptionModalOpen() { try{ dataLayer.push({ 'event':'subscriptionOpen' }); return {success:true,code:200,message:"subscriptionModalOpen successfully pushed"}; }catch(err) { return {success:false,code:500,message:err.message}; } } // subscriptionsuccess -- Whenever the user subscribes successfully to the Newsletter, this interaction should trigger a site interaction event with all relevant data fields. function subscriptionSuccess() { try{ dataLayer.push({ 'event':'subscriptionSuccess' }); return {success:true,code:200,message:"subscriptionSuccess successfully pushed"}; }catch(err) { return {success:false,code:500,message:err.message}; } } // contactFormOpen -- Whenever the user opens the contact form modal, this interaction should trigger a site interaction event with all relevant data fields. function contactFormOpen() { try{ dataLayer.push({ 'event':'contactFormOpen' }); return {success:true,code:200,message:"contactFormOpen successfully pushed"}; }catch(err) { return {success:false,code:500,message:err.message}; } } // contactFormSubmission -- Whenever the user opens the contact form modal, this interaction should trigger a site interaction event with all relevant data fields. function contactFormSubmission() { try{ dataLayer.push({ 'event':'contactFormSuccess' }); return {success:true,code:200,message:"contactFormSubmission successfully pushed"}; }catch(err) { return {success:false,code:500,message:err.message}; } } function push(_parameters) { if(_parameters.event){ try{ dataLayer.push(_parameters); return {success:true,code:200,message:_parameters.event+" successfully pushed"}; }catch(err) { return {success:false,code:500,message:err.message}; } }else{ return {success:false,code:500,message:"Event is required"} } } function promotionImpression(_promotion) { var eventName = "promoView"; if(_promotion && track.isPromotion(_promotion)){ try{ dataLayer.push({ 'event': eventName, 'promotion': _promotion }); return {success:true,code:200,message: eventName+" successfully pushed"}; }catch(err) { return {success:false,code:500,message:err.message}; } }else{ return {success:false,code:500,message:"Wrong Promotion structure"} } } function promotionsImpression(_parameters) { var eventName = "promoView"; if(_parameters && _parameters.promoView && Array.isArray(_parameters.promoView.promotions)){ var validProducts = true; _parameters.promoView.promotions.forEach(function(item){ if(!track.isPromotion(item)){ validProducts = false; } }); if(validProducts){ try{ dataLayer.push({ 'event': eventName, 'ecommerce': _parameters }); return {success:true,code:200,message: eventName+" successfully pushed"}; }catch(err) { return {success:false,code:500,message:err.message}; } }else{ return {success:false,code:500,message:"Wrong Promotion structure"} } }else{ return {success:false,code:500,message:"Wrong Promotion structure"} } } function promotionClick(_promotion) { var eventName = "promoClick"; if(_promotion && track.isPromotion(_promotion)){ try{ dataLayer.push({ 'event': eventName, 'promotion': _promotion }); return {success:true,code:200,message: eventName+" successfully pushed"}; }catch(err) { return {success:false,code:500,message:err.message}; } }else{ return {success:false,code:500,message:"Wrong Promotion structure"} } } function productImpression(_parameters) { var eventName = "productImpression"; if(_parameters && _parameters.currencyCode && _parameters.productImpression && Array.isArray(_parameters.productImpression)){ var validProducts = true; _parameters.productImpression.forEach(function(item){ if(!track.isProductImpression(item)){ validProducts = false; } }); if(validProducts){ try{ dataLayer.push({ 'event': eventName, 'ecommerce': _parameters }); return {success:true,code:200,message: eventName+" successfully pushed"}; }catch(err) { return {success:false,code:500,message:err.message}; } }else{ return {success:false,code:500,message:"Wrong productImpression structure"} } }else{ return {success:false,code:500,message:"Wrong eCommerce structure"} } } function productClick(_parameters) { var eventName = "productClick"; if(_parameters && _parameters.currencyCode && _parameters.productClick && _parameters.productClick.products && Array.isArray(_parameters.productClick.products) && _parameters.productClick.products.length > 0 && _parameters.productClick.actionField && track.isActionField(_parameters.productClick.actionField,eventName) ){ var validProducts = true; _parameters.productClick.products.forEach(function(item){ if(!track.isProduct(item, eventName)){ validProducts = false; } }); if(validProducts){ try{ dataLayer.push({ 'event': eventName, 'ecommerce': _parameters }); return {success:true,code:200,message: eventName + " successfully pushed"}; }catch(err) { return {success:false,code:500,message:err.message}; } }else{ return {success:false,code:500,message:"Wrong product structure"} } }else{ return {success:false,code:500,message:"Wrong eCommerce structure"} } } function pdpView(_parameters) { var eventName = "productDetail"; if(_parameters && _parameters.currencyCode && _parameters.productDetail && _parameters.productDetail.products && Array.isArray(_parameters.productDetail.products) && _parameters.productDetail.products.length > 0 && _parameters.productDetail.actionField && track.isActionField(_parameters.productDetail.actionField, eventName)){ var validProducts = true; _parameters.productDetail.products.forEach(function(item){ if(!track.isProduct(item, eventName)){ validProducts = false; } }); if(validProducts){ try{ dataLayer.push({ 'event': eventName, 'ecommerce': _parameters }); return {success:true,code:200,message: eventName + " successfully pushed"}; }catch(err) { return {success:false,code:500,message:err.message}; } }else{ return {success:false,code:500,message:"Wrong product structure"} } }else{ return {success:false,code:500,message:"Wrong eCommerce structure"} } } function addToCart(_parameters) { var eventName = "addToCart"; if(_parameters && _parameters.currencyCode && _parameters.addToCart && _parameters.addToCart.products && Array.isArray(_parameters.addToCart.products) && _parameters.addToCart.products.length > 0){ var validProducts = true; _parameters.addToCart.products.forEach(function(item){ if(!track.isProduct(item, eventName)){ validProducts = false; } }); if(validProducts){ try{ dataLayer.push({ 'event': eventName, 'ecommerce': _parameters }); return {success:true,code:200,message: eventName + " successfully pushed"}; }catch(err) { return {success:false,code:500,message:err.message}; } }else{ return {success:false,code:500,message:"Wrong product structure"} } }else{ return {success:false,code:500,message:"Wrong eCommerce structure"} } } function removeFromCart(_parameters) { var eventName = "removeFromCart"; if(_parameters && _parameters.currencyCode && _parameters.removeFromCart && _parameters.removeFromCart.products && Array.isArray(_parameters.removeFromCart.products) && _parameters.removeFromCart.products.length > 0 ){ var validProducts = true; _parameters.removeFromCart.products.forEach(function(item){ if(!track.isProduct(item, eventName)){ validProducts = false; } }); if(validProducts){ try{ dataLayer.push({ 'event': eventName, 'ecommerce': _parameters }); return {success:true,code:200,message: eventName + " successfully pushed"}; }catch(err) { return {success:false,code:500,message:err.message}; } }else{ return {success:false,code:500,message:"Wrong product structure"} } }else{ return {success:false,code:500,message:"Wrong eCommerce structure"} } } function checkout(_parameters) { var eventName = "checkout"; if(_parameters && _parameters.currencyCode && _parameters.checkout && _parameters.checkout.products && Array.isArray(_parameters.checkout.products) && _parameters.checkout.actionField && track.isActionField(_parameters.checkout.actionField, eventName) && _parameters.checkout.products.length > 0){ var validProducts = true; _parameters.checkout.products.forEach(function(item){ if(!track.isProduct(item, eventName)){ validProducts = false; } }); if(validProducts){ try{ dataLayer.push({ 'event': eventName, 'ecommerce': _parameters }); return {success:true,code:200,message: eventName + " successfully pushed"}; }catch(err) { return {success:false,code:500,message:err.message}; } }else{ return {success:false,code:500,message:"Wrong product structure"} } }else{ return {success:false,code:500,message:"Wrong eCommerce structure"} } } function transaction(_parameters) { var eventName = "transaction"; if(_parameters && _parameters.currencyCode && _parameters.transaction && _parameters.transaction.products && Array.isArray(_parameters.transaction.products) && _parameters.transaction.actionField && track.isActionField(_parameters.transaction.actionField, eventName) && _parameters.transaction.products.length > 0 ){ var validProducts = true; _parameters.transaction.products.forEach(function(item){ if(!track.isProduct(item, eventName)){ validProducts = false; } }); if(validProducts){ try{ dataLayer.push({ 'event': eventName, 'ecommerce': _parameters }); return {success:true,code:200,message: eventName + " successfully pushed"}; }catch(err) { return {success:false,code:500,message:err.message}; } }else{ return {success:false,code:500,message:"Wrong product structure"} } }else{ return {success:false,code:500,message:"Wrong eCommerce structure"} } } function storeLocatorLinkClick() { try{ dataLayer.push({ 'event':'storeLocatorLinkClick' }); return {success:true,code:200,message:"storeLocatorLinkClick successfully pushed"}; }catch(err) { return {success:false,code:500,message:err.message}; } } function storeLocatorOpen() { try{ dataLayer.push({ 'event':'storeLocatorOpen' }); return {success:true,code:200,message:"storeLocatorOpen successfully pushed"}; }catch(err) { return {success:false,code:500,message:err.message}; } } function storeLocatorClose() { try{ dataLayer.push({ 'event':'storeLocatorClose' }); return {success:true,code:200,message:"storeLocatorClose successfully pushed"}; }catch(err) { return {success:false,code:500,message:err.message}; } } // Available functions from outside the object return { loginRegistrationModalOpen:function(){ return loginRegistrationModalOpen(); }, loginSuccess:function(){ return loginSuccess(); }, registrationSuccess:function(){ return registrationSuccess(); }, subscriptionModalOpen:function(){ return subscriptionModalOpen(); }, subscriptionSuccess:function(){ return subscriptionSuccess(); }, contactFormOpen:function(){ return contactFormOpen(); }, contactFormSubmission:function(){ return contactFormSubmission(); }, push:function(_parameters){ return push(_parameters); }, promotionImpression:function(_promotion){ return promotionImpression(_promotion); }, promotionsImpression:function(_parameters){ return promotionsImpression(_parameters); }, promotionClick:function(_promotion){ return promotionClick(_promotion); }, productImpression:function(_parameters){ return productImpression(_parameters); }, productClick:function(_parameters){ return productClick(_parameters); }, pdpView:function(_parameters){ return pdpView(_parameters); }, addToCart:function(_parameters){ return addToCart(_parameters); }, removeFromCart:function(_parameters){ return removeFromCart(_parameters); }, checkout:function(_parameters){ return checkout(_parameters); }, transaction:function(_parameters){ return transaction(_parameters); }, //STORE LOCATOR FUNCTIONS storeLocatorLink:function(){ return storeLocatorLink(); }, storeLocatorOpen:function(){ return storeLocatorOpen(); }, storeLocatorClose:function(){ return storeLocatorClose(); } } }; track = trackManager(); // Equivalent to document.ready function r(f){/in/.test(document.readyState)?setTimeout('r('+f+')',9):f()}