@@ -19,6 +19,7 @@ import getHost from './get-host';
19
19
import baseCookie from './base-cookie' ;
20
20
import { AmplitudeServerZone , getEventLogApi } from './server-zone' ;
21
21
import ConfigManager from './config-manager' ;
22
+ import GlobalScope from './global-scope' ;
22
23
23
24
/**
24
25
* AmplitudeClient SDK API - instance constructor.
@@ -80,7 +81,7 @@ AmplitudeClient.prototype.init = function init(apiKey, opt_userId, opt_config, o
80
81
81
82
try {
82
83
_parseConfig ( this . options , opt_config ) ;
83
- if ( isBrowserEnv ( ) && window . Prototype !== undefined && Array . prototype . toJSON ) {
84
+ if ( isBrowserEnv ( ) && GlobalScope . Prototype !== undefined && Array . prototype . toJSON ) {
84
85
prototypeJsFix ( ) ;
85
86
utils . log . warn (
86
87
'Prototype.js injected Array.prototype.toJSON. Deleting Array.prototype.toJSON to prevent double-stringify' ,
@@ -243,7 +244,7 @@ AmplitudeClient.prototype.init = function init(apiKey, opt_userId, opt_config, o
243
244
// Monitoring just page exits because that is the most requested feature for now
244
245
// "If you're specifically trying to detect page unload events, the pagehide event is the best option."
245
246
// https://developer.mozilla.org/en-US/docs/Web/API/Window/pagehide_event
246
- window . addEventListener (
247
+ GlobalScope . addEventListener (
247
248
'pagehide' ,
248
249
( ) => {
249
250
handleVisibilityChange ( ) ;
@@ -254,7 +255,7 @@ AmplitudeClient.prototype.init = function init(apiKey, opt_userId, opt_config, o
254
255
}
255
256
} catch ( err ) {
256
257
utils . log . error ( err ) ;
257
- if ( type ( opt_config . onError ) === 'function' ) {
258
+ if ( opt_config && type ( opt_config . onError ) === 'function' ) {
258
259
opt_config . onError ( err ) ;
259
260
}
260
261
}
@@ -751,14 +752,14 @@ var _sendParamsReferrerUserProperties = function _sendParamsReferrerUserProperti
751
752
* @private
752
753
*/
753
754
AmplitudeClient . prototype . _getReferrer = function _getReferrer ( ) {
754
- return document . referrer ;
755
+ return typeof document !== 'undefined' ? document . referrer : '' ;
755
756
} ;
756
757
757
758
/**
758
759
* @private
759
760
*/
760
761
AmplitudeClient . prototype . _getUrlParams = function _getUrlParams ( ) {
761
- return location . search ;
762
+ return GlobalScope . location . search ;
762
763
} ;
763
764
764
765
/**
@@ -1779,7 +1780,7 @@ AmplitudeClient.prototype.sendEvents = function sendEvents() {
1779
1780
}
1780
1781
this . _sending = true ;
1781
1782
}
1782
- var protocol = this . options . forceHttps ? 'https' : 'https:' === window . location . protocol ? 'https' : 'http' ;
1783
+ var protocol = this . options . forceHttps ? 'https' : 'https:' === GlobalScope . location . protocol ? 'https' : 'http' ;
1783
1784
var url = protocol + '://' + this . options . apiEndpoint ;
1784
1785
1785
1786
// fetch events to send
0 commit comments