From 67b2a7de23394847f7a7680951c6afc5653e92a2 Mon Sep 17 00:00:00 2001 From: John Tran Date: Mon, 22 Feb 2021 13:18:09 -0800 Subject: [PATCH 1/3] change custom localStorage to ampLocalStorage to remove confusion --- src/metadata-storage.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/metadata-storage.js b/src/metadata-storage.js index 5fe78d3b..afa9fdcb 100644 --- a/src/metadata-storage.js +++ b/src/metadata-storage.js @@ -7,7 +7,7 @@ import Base64 from './base64'; import baseCookie from './base-cookie'; import Constants from './constants'; import getLocation from './get-location'; -import localStorage from './localstorage'; +import ampLocalStorage from './localstorage'; import topDomain from './top-domain'; const storageOptionExists = { @@ -94,7 +94,7 @@ class MetadataStorage { } break; case Constants.STORAGE_LOCAL: - localStorage.setItem(this.storageKey, value); + ampLocalStorage.setItem(this.storageKey, value); break; case Constants.STORAGE_COOKIES: baseCookie.set(this.getCookieStorageKey(), value, { @@ -113,7 +113,7 @@ class MetadataStorage { str = baseCookie.get(this.getCookieStorageKey() + '='); } if (!str) { - str = localStorage.getItem(this.storageKey); + str = ampLocalStorage.getItem(this.storageKey); } if (!str) { str = window.sessionStorage && window.sessionStorage.getItem(this.storageKey); From ff547e421d41d2965b638961a4fcf79013a9d814 Mon Sep 17 00:00:00 2001 From: John Tran Date: Tue, 23 Feb 2021 15:53:50 -0800 Subject: [PATCH 2/3] Add error handling for unavailable sessionStorage --- src/metadata-storage.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/metadata-storage.js b/src/metadata-storage.js index afa9fdcb..1164e238 100644 --- a/src/metadata-storage.js +++ b/src/metadata-storage.js @@ -9,6 +9,7 @@ import Constants from './constants'; import getLocation from './get-location'; import ampLocalStorage from './localstorage'; import topDomain from './top-domain'; +import utils from './utils'; const storageOptionExists = { [Constants.STORAGE_COOKIES]: true, @@ -116,7 +117,11 @@ class MetadataStorage { str = ampLocalStorage.getItem(this.storageKey); } if (!str) { - str = window.sessionStorage && window.sessionStorage.getItem(this.storageKey); + try { + str = window.sessionStorage && window.sessionStorage.getItem(this.storageKey); + } catch (e) { + utils.log.info(`window.sessionStorage unavailable. Reason: "${e}"`); + } } if (!str) { From d986696fed5d90bdf106123fcf88ad47f5338c88 Mon Sep 17 00:00:00 2001 From: John Tran Date: Tue, 23 Feb 2021 16:09:55 -0800 Subject: [PATCH 3/3] Add docs to option --- src/options.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/options.js b/src/options.js index 2de571dd..7ead5215 100644 --- a/src/options.js +++ b/src/options.js @@ -44,6 +44,7 @@ if (BUILD_COMPAT_REACT_NATIVE) { * @property {boolean} [saveParamsReferrerOncePerSession=`true`] - If `true`, then includeGclid, includeFbclid, includeReferrer, and includeUtm will only track their respective properties once per session. New values that come in during the middle of the user's session will be ignored. Set to false to always capture new values. * @property {boolean} [secureCookie=`false`] - If `true`, the amplitude cookie will be set with the Secure flag. * @property {number} [sessionTimeout=`30*60*1000` (30 min)] - The time between logged events before a new session starts in milliseconds. + * @property {string[]} [storage=`''`] - Sets storage strategy. Options are 'cookies', 'localStorage', 'sessionStorage', or `none`. Will override `disableCookies` option * @property {Object} [trackingOptions=`{ city: true, country: true, carrier: true, device_manufacturer: true, device_model: true, dma: true, ip_address: true, language: true, os_name: true, os_version: true, platform: true, region: true, version_name: true}`] - Type of data associated with a user. * @property {boolean} [unsetParamsReferrerOnNewSession=`false`] - If `false`, the existing `referrer` and `utm_parameter` values will be carried through each new session. If set to `true`, the `referrer` and `utm_parameter` user properties, which include `referrer`, `utm_source`, `utm_medium`, `utm_campaign`, `utm_term`, and `utm_content`, will be set to `null` upon instantiating a new session. Note: This only works if `includeReferrer` or `includeUtm` is set to `true`. * @property {string} [unsentKey=`amplitude_unsent`] - localStorage key that stores unsent events.