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
16 changes: 7 additions & 9 deletions apps/src/lib/util/firehose.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @file Provides clients to AWS Firehose, whose data is imported into AWS Redshift. */

import AWS from 'aws-sdk';
import {createUuid, trySetLocalStorage} from '@cdo/apps/utils';
import {createUuid, trySetLocalStorage, tryGetLocalStorage} from '@cdo/apps/utils';

/**
* A barebones client for posting data to an AWS Firehose stream.
Expand Down Expand Up @@ -112,17 +112,15 @@ class FirehoseClient {
* Returns a unique user ID that is persisted across sessions through local
* storage.
* WARNING: Mutates local storage if an analyticsID has not already been set.
* @return {string | null} A unique user ID.
* @return {string} A unique user ID.
*/
getAnalyticsUuid() {
if (!!window.localStorage && !!window.localStorage.getItem("analyticsID")) {
return window.localStorage.getItem("analyticsID");
let analytics_uuid = tryGetLocalStorage("analyticsID", null);
if (!analytics_uuid) {
analytics_uuid = createUuid();
}
let analytics_uuid = createUuid();
if (trySetLocalStorage("analyticsID", analytics_uuid)) {
return analytics_uuid;
}
return null;
trySetLocalStorage("analyticsID", analytics_uuid);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the format of the analytics UUID the same as the format of the local storage ID?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is where that's populated.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right, never mind. Ducks in shame.

return analytics_uuid;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions apps/src/redux/instructions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* off of those actions.
*/

import { trySetLocalStorage } from '../utils';
import { trySetLocalStorage, tryGetLocalStorage } from '../utils';

const SET_CONSTANTS = 'instructions/SET_CONSTANTS';
const TOGGLE_INSTRUCTIONS_COLLAPSED = 'instructions/TOGGLE_INSTRUCTIONS_COLLAPSED';
Expand Down Expand Up @@ -306,7 +306,7 @@ export const determineInstructionsConstants = config => {
// instructions or if it is the first level in the stage, always show
// the overlay. Otherwise, show it exactly once on the very first
// level a user looks at.
let overlaySeen = localStorage.getItem(LOCALSTORAGE_OVERLAY_SEEN_FLAG);
let overlaySeen = tryGetLocalStorage(LOCALSTORAGE_OVERLAY_SEEN_FLAG, false);
let shouldShowOverlay = hasInstructionsToShow &&
(config.level.instructionsImportant || config.levelPosition === 1 || !overlaySeen);
if (shouldShowOverlay) {
Expand Down
13 changes: 13 additions & 0 deletions apps/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,19 @@ export function degreesToRadians(degrees) {
return degrees * (Math.PI / 180);
}

export function tryGetLocalStorage(key, defaultValue) {
if (defaultValue === undefined) {
throw "tryGetLocalStorage requires defaultValue";
}
let returnValue = defaultValue;
try {
returnValue = localStorage.getItem(key);
} catch (e) {
// Ignore, return default
}
return returnValue;
}

/**
* Simple wrapper around localStorage.setItem that catches any exceptions (for
* example when we call setItem in Safari's private mode)
Expand Down