Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/metadata-storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ 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';
import utils from './utils';

const storageOptionExists = {
[Constants.STORAGE_COOKIES]: true,
Expand Down Expand Up @@ -94,7 +95,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, {
Expand All @@ -113,10 +114,14 @@ 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);
try {
str = window.sessionStorage && window.sessionStorage.getItem(this.storageKey);
} catch (e) {
utils.log.info(`window.sessionStorage unavailable. Reason: "${e}"`);
}
}

if (!str) {
Expand Down
1 change: 1 addition & 0 deletions src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down