Skip to content

Commit

Permalink
fix: allow amplitude to be imported/required during SSR (#436)
Browse files Browse the repository at this point in the history
  • Loading branch information
seanparmelee authored Nov 2, 2021
1 parent 57a47ca commit ff7d8ef
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Entry point
import Amplitude from './amplitude';

const old = window.amplitude || {};
const old = (typeof window !== 'undefined' && window.amplitude) || {};
const newInstance = new Amplitude();
newInstance._q = old._q || [];

Expand Down
3 changes: 2 additions & 1 deletion src/language.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var getLanguage = function () {
return (
(navigator && ((navigator.languages && navigator.languages[0]) || navigator.language || navigator.userLanguage)) ||
(typeof navigator !== 'undefined' &&
((navigator.languages && navigator.languages[0]) || navigator.language || navigator.userLanguage)) ||
''
);
};
Expand Down
2 changes: 1 addition & 1 deletion src/localstorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ if (BUILD_COMPAT_LOCAL_STORAGE) {

if (windowLocalStorageAvailable()) {
localStorage = window.localStorage;
} else if (window.globalStorage) {
} else if (typeof window !== 'undefined' && window.globalStorage) {
// Firefox 2-3 use globalStorage
// See https://developer.mozilla.org/en/dom/storage#globalStorage
try {
Expand Down

0 comments on commit ff7d8ef

Please sign in to comment.