(function () { (window._bigin = window._bigin || {}).storage = window._bigin.storage || { _items: (function () { try { return JSON.parse(window.localStorage.getItem('bigin-storage')) || {}; } catch (e) { return {}; } })(), _flush: function () { var self = this; var items = Object.keys(this._items).reduce(function (acc, key) { if (!self._items[key].expiration) { return acc; } if (self._items[key].expiration < (new Date()).getTime()) { return acc; } acc[key] = self._items[key]; return acc; }, {}); window.localStorage.setItem('bigin-storage', JSON.stringify(items)); }, getItem: function (key) { if (!this._items.hasOwnProperty(key)) { return undefined; } if (this._items[key].expiration && this._items[key].expiration < (new Date()).getTime()) { return undefined; } return this._items[key].value; }, setItem: function (key, value, milliseconds) { this._items[key] = { value: value, expiration: milliseconds ? (new Date()).getTime() + milliseconds : undefined, }; this._flush(); }, hasItem: function (key) { return !!this.getItem(key); }, }; })(); (function (window, document, scriptTagName, gtmId, dataLayerName) { (function (w, d, s, l, i) { w[l] = w[l] || []; w[l].push({ 'gtm.start': new Date().getTime(), event: 'gtm.js', }); var f = d.getElementsByTagName(s)[0], j = d.createElement(s), dl = l != 'dataLayer' ? '&l=' + l : ''; j.async = true; j.src = 'https://www.googletagmanager.com/gtm.js?id=' + i + dl; f.parentNode.insertBefore(j, f); })(window, document, scriptTagName, dataLayerName, gtmId); var bigin = { __isDebug: (function () { return JSON.parse(window.localStorage.getItem('isBiginDebug')); })(), __console: { error: function (...args) { if (!bigin.__isDebug) { return; } window.console.error(new Date().toISOString(), '[biginMakeshopPlugin]', ...args); }, log: function (...args) { if (!bigin.__isDebug) { return; } window.console.log(new Date().toISOString(), '[biginMakeshopPlugin]', ...args); }, }, bootstrap: function () { this.__bootstrapCommonPage(); }, __bootstrapCommonPage: function () { try { var page = bigin.__buildCommonPage(); if (!page) { return; } if (page.isLogin) { bigin.__fetchAndNotifyUser(); } } catch (e) { bigin.__console.error(e); } }, __buildCommonPage: function () { var page = { isLogin: undefined, }; page.isLogin = window.IS_LOGIN === 'true'; return page; }, __fetchAndNotifyUser: function () { var storageKey = 'getProfileDataResponse'; var self = this; fetch('//' + window.location.hostname + '/shop/mp_info.action.html', { method: 'POST', headers: { 'content-type': 'application/x-www-form-urlencoded', }, body: 'action_mode=get_token&type=bigin', }).then(function (response) { var data = response.json(); if (data.success === false) { throw new Error(data.msg); } return data; }).then(function (data) { var token = data.data; fetch('//' + window.location.hostname + '/shop/mp_info.action.html', { method: 'POST', headers: { 'content-type': 'application/x-www-form-urlencoded', }, body: 'action_mode=get_profile_data&type=bigin&token=' + token, }).then(function (response) { var data = response.json(); if (data.success === false) { throw new Error(data.msg); } return data; }).then(function (data) { window._bigin.storage.setItem(storageKey, data); self.__notify(storageKey, data); }).catch(function (error) { self.__console.error(error); }); }).catch(function (error) { self.__console.error(error); }); }, __notify: function (key, value) { this.__console.log(key, value); window[dataLayerName].push({ event: 'bg.notify', key: key, value: value, }); }, }; bigin.bootstrap(); }) (window, document, 'script', "GTM-WS25XC3B", 'dataLayer');