@mparticle/web-inspectlet-kit 2.0.1 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/Inspectlet.common.js +149 -132
  2. package/package.json +39 -26
@@ -26,185 +26,202 @@ function isObject(val) {
26
26
  // See the License for the specific language governing permissions and
27
27
  // limitations under the License.
28
28
 
29
-
30
29
 
31
- var MessageType = {
30
+
31
+ var MessageType = {
32
32
  SessionStart: 1,
33
33
  SessionEnd: 2,
34
34
  PageView: 3,
35
35
  PageEvent: 4,
36
36
  CrashReport: 5,
37
37
  OptOut: 6,
38
- Commerce: 16
38
+ Commerce: 16,
39
39
  },
40
- name = 'Inspectlet',
41
- moduleId = 61;
40
+ name = 'Inspectlet',
41
+ moduleId = 61;
42
42
 
43
- var constructor = function () {
44
- var self = this,
45
- isInitialized = false,
46
- forwarderSettings,
47
- reportingService,
48
- isTesting = false;
43
+ var constructor = function() {
44
+ var self = this,
45
+ isInitialized = false,
46
+ forwarderSettings,
47
+ reportingService,
48
+ isTesting = false;
49
49
 
50
- self.name = name;
50
+ self.name = name;
51
51
 
52
- function getIdentityTypeName(identityType) {
53
- return mParticle.IdentityType.getName(identityType);
54
- }
52
+ function getIdentityTypeName(identityType) {
53
+ return mParticle.IdentityType.getName(identityType);
54
+ }
55
55
 
56
- function reportEvent(event) {
57
- if (reportingService) {
58
- reportingService(self, event);
59
- }
56
+ function reportEvent(event) {
57
+ if (reportingService) {
58
+ reportingService(self, event);
60
59
  }
60
+ }
61
61
 
62
- function processEvent(event) {
63
- if (isInitialized) {
64
- try {
65
- if (event.EventDataType == MessageType.PageEvent) {
66
- if (event.EventCategory == window.mParticle.EventType.Transaction) {
67
- logTransaction(event);
68
- reportEvent(event);
69
- return 'Successfully sent to ' + name;
70
- }
71
- else if (event.EventCategory == window.mParticle.EventType.Navigation) {
72
- __insp.push(["virtualPage"]);
73
- reportEvent(event);
74
-
75
- return 'Successfully sent virtual page view to ' + name;
76
- }
77
- }
78
- else if (event.EventDataType == MessageType.Commerce) {
62
+ function processEvent(event) {
63
+ if (isInitialized) {
64
+ try {
65
+ if (event.EventDataType == MessageType.PageEvent) {
66
+ if (
67
+ event.EventCategory ==
68
+ window.mParticle.EventType.Transaction
69
+ ) {
79
70
  logTransaction(event);
71
+ reportEvent(event);
72
+ return 'Successfully sent to ' + name;
73
+ } else if (
74
+ event.EventCategory ==
75
+ window.mParticle.EventType.Navigation
76
+ ) {
77
+ __insp.push(['virtualPage']);
78
+ reportEvent(event);
79
+
80
+ return 'Successfully sent virtual page view to ' + name;
80
81
  }
81
-
82
- return 'Ignoring non-transaction event for ' + name;
83
- }
84
- catch (e) {
85
- return 'Failed to send to: ' + name + ' ' + e;
82
+ } else if (event.EventDataType == MessageType.Commerce) {
83
+ logTransaction(event);
86
84
  }
87
- }
88
85
 
89
- return 'Can\'t send to forwarder ' + name + ', not initialized';
86
+ return 'Ignoring non-transaction event for ' + name;
87
+ } catch (e) {
88
+ return 'Failed to send to: ' + name + ' ' + e;
89
+ }
90
90
  }
91
91
 
92
- function logTransaction(data) {
93
- __insp.push(['tagSession', "purchase"]);
94
- }
92
+ return "Can't send to forwarder " + name + ', not initialized';
93
+ }
95
94
 
96
- function setUserAttribute(key, value) {
97
- var attributeDict;
95
+ function logTransaction(data) {
96
+ __insp.push(['tagSession', 'purchase']);
97
+ }
98
98
 
99
- if (isInitialized) {
100
- if (value) {
101
- attributeDict = {};
102
- attributeDict[key] = value;
103
- __insp.push(['tagSession', attributeDict]);
104
- }
105
- else {
106
- __insp.push(['tagSession', key]);
107
- }
108
- }
109
- else {
110
- return 'Can\'t call setUserAttribute on forwarder ' + name + ', not initialized';
111
- }
112
- }
99
+ function setUserAttribute(key, value) {
100
+ var attributeDict;
113
101
 
114
- function setUserIdentity(id, type) {
115
- if (isInitialized) {
116
- setUserAttribute(getIdentityTypeName(type), id);
117
- }
118
- else {
119
- return 'Can\'t call setUserIdentity on forwarder ' + name + ', not initialized';
102
+ if (isInitialized) {
103
+ if (value) {
104
+ attributeDict = {};
105
+ attributeDict[key] = value;
106
+ __insp.push(['tagSession', attributeDict]);
107
+ } else {
108
+ __insp.push(['tagSession', key]);
120
109
  }
110
+ } else {
111
+ return (
112
+ "Can't call setUserAttribute on forwarder " +
113
+ name +
114
+ ', not initialized'
115
+ );
121
116
  }
117
+ }
122
118
 
123
- function initForwarder(settings, service, testMode) {
124
- forwarderSettings = settings;
125
- reportingService = service;
126
- isTesting = testMode;
127
-
128
- try {
129
- function addInspectlet() {
130
- function __ldinsp() {
131
- var insp = document.createElement('script');
132
- insp.type = 'text/javascript';
133
- insp.async = true;
134
- insp.id = "inspsync";
135
- insp.src = ('https:' == document.location.protocol ? 'https' : 'http') + '://cdn.inspectlet.com/inspectlet.js';
136
- var head = document.getElementsByTagName('head')[0];
137
- head.appendChild(insp);
138
- }
119
+ function setUserIdentity(id, type) {
120
+ if (isInitialized) {
121
+ setUserAttribute(getIdentityTypeName(type), id);
122
+ } else {
123
+ return (
124
+ "Can't call setUserIdentity on forwarder " +
125
+ name +
126
+ ', not initialized'
127
+ );
128
+ }
129
+ }
139
130
 
140
- if (window.attachEvent) {
141
- window.attachEvent('onload', __ldinsp);
142
- }
143
- else {
144
- window.addEventListener('load', __ldinsp, false);
145
- }
131
+ function initForwarder(settings, service, testMode) {
132
+ forwarderSettings = settings;
133
+ reportingService = service;
134
+ isTesting = testMode;
135
+
136
+ try {
137
+ function addInspectlet() {
138
+ function __ldinsp() {
139
+ var insp = document.createElement('script');
140
+ insp.type = 'text/javascript';
141
+ insp.async = true;
142
+ insp.id = 'inspsync';
143
+ insp.src =
144
+ ('https:' == document.location.protocol
145
+ ? 'https'
146
+ : 'http') + '://cdn.inspectlet.com/inspectlet.js';
147
+ var head = document.getElementsByTagName('head')[0];
148
+ head.appendChild(insp);
146
149
  }
147
150
 
148
- window.__insp = window.__insp || [];
149
- __insp.push(['wid', forwarderSettings.wId]);
150
-
151
- if (isTesting === false) {
152
- addInspectlet();
151
+ if (window.attachEvent) {
152
+ window.attachEvent('onload', __ldinsp);
153
+ } else {
154
+ window.addEventListener('load', __ldinsp, false);
153
155
  }
156
+ }
154
157
 
155
- isInitialized = true;
158
+ window.__insp = window.__insp || [];
159
+ __insp.push(['wid', forwarderSettings.wId]);
156
160
 
157
- return 'Successfully initialized: ' + name;
158
- }
159
- catch (e) {
160
- return 'Failed to initialize: ' + name;
161
+ if (isTesting === false) {
162
+ addInspectlet();
161
163
  }
162
- }
163
164
 
164
- this.init = initForwarder;
165
- this.process = processEvent;
166
- this.setUserAttribute = setUserAttribute;
167
- this.setUserIdentity = setUserIdentity;
168
- };
169
- function getId() {
170
- return moduleId;
171
- }
165
+ isInitialized = true;
172
166
 
173
- function register(config) {
174
- if (!config) {
175
- window.console.log('You must pass a config object to register the kit ' + name);
176
- return;
167
+ return 'Successfully initialized: ' + name;
168
+ } catch (e) {
169
+ return 'Failed to initialize: ' + name;
177
170
  }
171
+ }
178
172
 
179
- if (!isObject(config)) {
180
- window.console.log('\'config\' must be an object. You passed in a ' + typeof config);
181
- return;
182
- }
173
+ this.init = initForwarder;
174
+ this.process = processEvent;
175
+ this.setUserAttribute = setUserAttribute;
176
+ this.setUserIdentity = setUserIdentity;
177
+ };
178
+ function getId() {
179
+ return moduleId;
180
+ }
183
181
 
184
- if (isObject(config.kits)) {
185
- config.kits[name] = {
186
- constructor: constructor
187
- };
188
- } else {
189
- config.kits = {};
190
- config.kits[name] = {
191
- constructor: constructor
192
- };
193
- }
194
- window.console.log('Successfully registered ' + name + ' to your mParticle configuration');
182
+ function register(config) {
183
+ if (!config) {
184
+ console.log(
185
+ 'You must pass a config object to register the kit ' + name
186
+ );
187
+ return;
188
+ }
189
+
190
+ if (!isObject(config)) {
191
+ console.log(
192
+ "'config' must be an object. You passed in a " + typeof config
193
+ );
194
+ return;
195
195
  }
196
196
 
197
+ if (isObject(config.kits)) {
198
+ config.kits[name] = {
199
+ constructor: constructor,
200
+ };
201
+ } else {
202
+ config.kits = {};
203
+ config.kits[name] = {
204
+ constructor: constructor,
205
+ };
206
+ }
207
+ console.log(
208
+ 'Successfully registered ' + name + ' to your mParticle configuration'
209
+ );
210
+ }
211
+
212
+ if (typeof window !== 'undefined') {
197
213
  if (window && window.mParticle && window.mParticle.addForwarder) {
198
214
  window.mParticle.addForwarder({
199
215
  name: name,
200
216
  constructor: constructor,
201
- getId: getId
217
+ getId: getId,
202
218
  });
203
219
  }
220
+ }
204
221
 
205
- var Inspectlet = {
206
- register: register
207
- };
222
+ var Inspectlet = {
223
+ register: register,
224
+ };
208
225
  var Inspectlet_1 = Inspectlet.register;
209
226
 
210
227
  exports.default = Inspectlet;
package/package.json CHANGED
@@ -1,28 +1,41 @@
1
1
  {
2
- "name": "@mparticle/web-inspectlet-kit",
3
- "version": "2.0.1",
4
- "author": "mParticle Developers <developers@mparticle.com> (https://www.mparticle.com)",
5
- "description": "mParticle integration sdk for Inspectlet",
6
- "main": "dist/Inspectlet.common.js",
7
- "browser": "dist/Inspectlet.common.js",
8
- "files": [
9
- "dist/Inspectlet.common.js"
10
- ],
11
- "repository": "https://github.com/mparticle-integrations/mparticle-javascript-integration-inspectlet",
12
- "scripts": {
13
- "build": "rollup --config rollup.config.js",
14
- "watch": "rollup --config rollup.config.js -w"
15
- },
16
- "devDependencies": {
17
- "should": "^7.1.0",
18
- "mocha": "^2.3.2",
19
- "rollup": "^1.13.1",
20
- "rollup-plugin-commonjs": "^10.0.0",
21
- "rollup-plugin-node-resolve": "^5.0.1"
22
- },
23
- "dependencies": {
24
- "isobject": "^4.0.0",
25
- "@mparticle/web-sdk": "^2.11.1"
26
- },
27
- "license": "Apache-2.0"
2
+ "name": "@mparticle/web-inspectlet-kit",
3
+ "version": "3.1.0",
4
+ "author": "mParticle Developers <developers@mparticle.com> (https://www.mparticle.com)",
5
+ "description": "mParticle integration sdk for Inspectlet",
6
+ "main": "dist/Inspectlet.common.js",
7
+ "browser": "dist/Inspectlet.common.js",
8
+ "files": [
9
+ "dist/Inspectlet.common.js"
10
+ ],
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/mParticle/mparticle-web-sdk",
14
+ "directory": "kits/inspectlet"
15
+ },
16
+ "scripts": {
17
+ "build": "rollup --config rollup.config.js",
18
+ "watch": "rollup --config rollup.config.js -w",
19
+ "test": "node test/boilerplate/test-karma.js"
20
+ },
21
+ "devDependencies": {
22
+ "chai": "^4.2.0",
23
+ "karma": "^5.1.0",
24
+ "karma-chai": "^0.1.0",
25
+ "karma-chrome-launcher": "^3.1.0",
26
+ "karma-firefox-launcher": "^1.3.0",
27
+ "karma-mocha": "^2.0.1",
28
+ "mocha": "^2.5.3",
29
+ "rollup": "^1.13.1",
30
+ "rollup-plugin-commonjs": "^10.0.0",
31
+ "rollup-plugin-node-resolve": "^5.0.1",
32
+ "shelljs": "^0.8.4",
33
+ "should": "^7.1.0",
34
+ "watchify": "^3.11.1"
35
+ },
36
+ "dependencies": {
37
+ "isobject": "^4.0.0",
38
+ "@mparticle/web-sdk": "^3.0.0"
39
+ },
40
+ "license": "Apache-2.0"
28
41
  }