Skip to content

Commit 087c220

Browse files
authored
Bugfix - Check window for node environments (#9)
1 parent d1042b9 commit 087c220

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

src/LocalyticsEventForwarder.js

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

315315
function register(config) {
316316
if (!config) {
317-
window.console.log('You must pass a config object to register the kit ' + name);
317+
console.log('You must pass a config object to register the kit ' + name);
318318
return;
319319
}
320320

321321
if (!isobject(config)) {
322-
window.console.log('\'config\' must be an object. You passed in a ' + typeof config);
322+
console.log('\'config\' must be an object. You passed in a ' + typeof config);
323323
return;
324324
}
325325

@@ -333,15 +333,17 @@
333333
constructor: constructor
334334
};
335335
}
336-
window.console.log('Successfully registered ' + name + ' to your mParticle configuration');
336+
console.log('Successfully registered ' + name + ' to your mParticle configuration');
337337
}
338338

339-
if (window && window.mParticle && window.mParticle.addForwarder) {
340-
window.mParticle.addForwarder({
341-
name: name,
342-
constructor: constructor,
343-
getId: getId
344-
});
339+
if (typeof window !== 'undefined') {
340+
if (window && window.mParticle && window.mParticle.addForwarder) {
341+
window.mParticle.addForwarder({
342+
name: name,
343+
constructor: constructor,
344+
getId: getId
345+
});
346+
}
345347
}
346348

347349
module.exports = {

0 commit comments

Comments
 (0)