@@ -39,7 +39,6 @@ var AmplitudeClient = function AmplitudeClient(instanceName) {
3939 this . _instanceName = utils . isEmptyString ( instanceName ) ? Constants . DEFAULT_INSTANCE : instanceName . toLowerCase ( ) ;
4040 this . _unsentEvents = [ ] ;
4141 this . _unsentIdentifys = [ ] ;
42- this . _ua = new UAParser ( navigator . userAgent ) . getResult ( ) ;
4342 this . options = { ...DEFAULT_OPTIONS , trackingOptions : { ...DEFAULT_OPTIONS . trackingOptions } } ;
4443 this . cookieStorage = new cookieStorage ( ) . getStorage ( ) ;
4544 this . _q = [ ] ; // queue for proxied functions before script load
@@ -61,7 +60,8 @@ var AmplitudeClient = function AmplitudeClient(instanceName) {
6160 // used to integrate with experiment SDK (client-side exposure tracking & real-time user properties)
6261 this . _connector = null ;
6362
64- this . _userAgent = ( navigator && navigator . userAgent ) || null ;
63+ this . _userAgent = ( typeof navigator !== 'undefined' && navigator && navigator . userAgent ) || null ;
64+ this . _ua = new UAParser ( this . _userAgent ) . getResult ( ) ;
6565} ;
6666
6767AmplitudeClient . prototype . Identify = Identify ;
@@ -249,7 +249,7 @@ AmplitudeClient.prototype.init = function init(apiKey, opt_userId, opt_config, o
249249 }
250250
251251 const onExitPage = this . options . onExitPage ;
252- if ( type ( onExitPage ) === 'function' ) {
252+ if ( type ( onExitPage ) === 'function' && GlobalScope . addEventListener ) {
253253 if ( ! this . pageHandlersAdded ) {
254254 this . pageHandlersAdded = true ;
255255
@@ -1865,7 +1865,7 @@ AmplitudeClient.prototype.sendEvents = function sendEvents() {
18651865 checksum : md5 ( Constants . API_VERSION + this . options . apiKey + events + uploadTime ) ,
18661866 } ;
18671867
1868- if ( this . options . transport === Constants . TRANSPORT_BEACON ) {
1868+ if ( this . options . transport === Constants . TRANSPORT_BEACON && typeof navigator !== 'undefined' ) {
18691869 const success = navigator . sendBeacon ( url , new URLSearchParams ( data ) ) ;
18701870
18711871 if ( success ) {
0 commit comments