Skip to content

Commit ff7d8ef

Browse files
authored
fix: allow amplitude to be imported/required during SSR (#436)
1 parent 57a47ca commit ff7d8ef

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Entry point
22
import Amplitude from './amplitude';
33

4-
const old = window.amplitude || {};
4+
const old = (typeof window !== 'undefined' && window.amplitude) || {};
55
const newInstance = new Amplitude();
66
newInstance._q = old._q || [];
77

src/language.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var getLanguage = function () {
22
return (
3-
(navigator && ((navigator.languages && navigator.languages[0]) || navigator.language || navigator.userLanguage)) ||
3+
(typeof navigator !== 'undefined' &&
4+
((navigator.languages && navigator.languages[0]) || navigator.language || navigator.userLanguage)) ||
45
''
56
);
67
};

src/localstorage.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ if (BUILD_COMPAT_LOCAL_STORAGE) {
2626

2727
if (windowLocalStorageAvailable()) {
2828
localStorage = window.localStorage;
29-
} else if (window.globalStorage) {
29+
} else if (typeof window !== 'undefined' && window.globalStorage) {
3030
// Firefox 2-3 use globalStorage
3131
// See https://developer.mozilla.org/en/dom/storage#globalStorage
3232
try {

0 commit comments

Comments
 (0)