UNPKG

4.71 kBJavaScriptView Raw
1(function webpackUniversalModuleDefinition(root, factory) {
2 if(typeof exports === 'object' && typeof module === 'object')
3 module.exports = factory();
4 else if(typeof define === 'function' && define.amd)
5 define([], factory);
6 else {
7 var a = factory();
8 for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
9 }
10})(this, function() {
11return /******/ (function(modules) { // webpackBootstrap
12/******/ // The module cache
13/******/ var installedModules = {};
14
15/******/ // The require function
16/******/ function __webpack_require__(moduleId) {
17
18/******/ // Check if module is in cache
19/******/ if(installedModules[moduleId])
20/******/ return installedModules[moduleId].exports;
21
22/******/ // Create a new module (and put it into the cache)
23/******/ var module = installedModules[moduleId] = {
24/******/ exports: {},
25/******/ id: moduleId,
26/******/ loaded: false
27/******/ };
28
29/******/ // Execute the module function
30/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
31
32/******/ // Flag the module as loaded
33/******/ module.loaded = true;
34
35/******/ // Return the exports of the module
36/******/ return module.exports;
37/******/ }
38
39
40/******/ // expose the modules object (__webpack_modules__)
41/******/ __webpack_require__.m = modules;
42
43/******/ // expose the module cache
44/******/ __webpack_require__.c = installedModules;
45
46/******/ // __webpack_public_path__
47/******/ __webpack_require__.p = "";
48
49/******/ // Load entry module and return exports
50/******/ return __webpack_require__(0);
51/******/ })
52/************************************************************************/
53/******/ ([
54/* 0 */
55/***/ function(module, exports, __webpack_require__) {
56
57 'use strict';
58
59 module.exports = __webpack_require__(9);
60
61/***/ },
62/* 1 */,
63/* 2 */,
64/* 3 */,
65/* 4 */,
66/* 5 */,
67/* 6 */,
68/* 7 */,
69/* 8 */,
70/* 9 */
71/***/ function(module, exports, __webpack_require__) {
72
73 'use strict';
74
75 var _require = __webpack_require__(10),
76 filterEcommEvents = _require.filterEcommEvents,
77 isEcommEvent = _require.isEcommEvent;
78
79 function GoogleAnalytics(events) {
80 if (typeof window === 'undefined') {
81 return;
82 }
83 if (typeof window.ga !== 'function') {
84 throw new Error('window.ga is not defined, Have you forgotten to include Google Analytics?');
85 }
86 events.forEach(function (event) {
87 if (isEcommEvent(event)) {
88 var trackerId = event.customTrackerId ? event.customTrackerId + '.' : '';
89 var callEvent = function callEvent(type) {
90 return {
91 addItem: function addItem() {
92 return window.ga(trackerId + 'ecommerce:addItem', filterEcommEvents(event));
93 },
94 addTransaction: function addTransaction() {
95 return window.ga(trackerId + 'ecommerce:addTransaction', filterEcommEvents(event));
96 },
97 ecommClear: function ecommClear() {
98 return window.ga(trackerId + 'ecommerce:clear');
99 },
100 ecommSend: function ecommSend() {
101 return window.ga(trackerId + 'ecommerce:send');
102 }
103 }[type]();
104 };
105
106 callEvent(event.hitType);
107 } else {
108 if (event.hitType === 'pageview') {
109 window.ga('set', 'page', event.page);
110 }
111 window.ga('send', event);
112 }
113 });
114 }
115
116 module.exports = { GoogleAnalytics: GoogleAnalytics };
117
118/***/ },
119/* 10 */
120/***/ function(module, exports, __webpack_require__) {
121
122 'use strict';
123
124 var _require = __webpack_require__(11),
125 ensure = _require.ensure;
126
127 var _require2 = __webpack_require__(12),
128 filterEcommEvents = _require2.filterEcommEvents,
129 isEcommEvent = _require2.isEcommEvent;
130
131 module.exports = {
132 ensure: ensure,
133 filterEcommEvents: filterEcommEvents,
134 isEcommEvent: isEcommEvent
135 };
136
137/***/ },
138/* 11 */
139/***/ function(module, exports) {
140
141 "use strict";
142
143 var ensure = function ensure(isValid, eventDef) {
144 return function () {
145 var event = eventDef.apply(undefined, arguments);
146 return isValid(event) ? event : null;
147 };
148 };
149
150 module.exports = { ensure: ensure };
151
152/***/ },
153/* 12 */
154/***/ function(module, exports) {
155
156 'use strict';
157
158 var filterEcommEvents = function filterEcommEvents(obj) {
159 var newObj = {};
160 Object.keys(obj).forEach(function (key) {
161 if (key !== 'hitType' && key !== 'customTrackerId') {
162 newObj[key] = obj[key];
163 }
164 });
165 return newObj;
166 };
167
168 var isEcommEvent = function isEcommEvent(event) {
169 return ['addTransaction', 'addItem', 'ecommSend', 'ecommClear'].indexOf(event.hitType) > -1;
170 };
171
172 module.exports = {
173 filterEcommEvents: filterEcommEvents,
174 isEcommEvent: isEcommEvent
175 };
176
177/***/ }
178/******/ ])
179});
180;
\No newline at end of file