Skip to content

Commit ae39a18

Browse files
committed
Bugfix - Check window for node environments (#9)
1 parent 8c1a21b commit ae39a18

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/KissMetricsForwarder.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,12 @@
273273

274274
function register(config) {
275275
if (!config) {
276-
window.console.log('You must pass a config object to register the kit ' + name);
276+
console.log('You must pass a config object to register the kit ' + name);
277277
return;
278278
}
279279

280280
if (!isobject(config)) {
281-
window.console.log('\'config\' must be an object. You passed in a ' + typeof config);
281+
console.log('\'config\' must be an object. You passed in a ' + typeof config);
282282
return;
283283
}
284284

@@ -292,15 +292,17 @@
292292
constructor: constructor
293293
};
294294
}
295-
window.console.log('Successfully registered ' + name + ' to your mParticle configuration');
295+
console.log('Successfully registered ' + name + ' to your mParticle configuration');
296296
}
297297

298-
if (window && window.mParticle && window.mParticle.addForwarder) {
299-
window.mParticle.addForwarder({
300-
name: name,
301-
constructor: constructor,
302-
getId: getId
303-
});
298+
if (typeof window !== 'undefined') {
299+
if (window && window.mParticle && window.mParticle.addForwarder) {
300+
window.mParticle.addForwarder({
301+
name: name,
302+
constructor: constructor,
303+
getId: getId
304+
});
305+
}
304306
}
305307

306308
module.exports = {

0 commit comments

Comments
 (0)