Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consent & local storage config flag #1064

Merged
merged 10 commits into from
Oct 25, 2023
Merged

Conversation

shandilya3
Copy link
Collaborator

@shandilya3 shandilya3 commented Oct 24, 2023

Description

  • personalizationStorageEnabled is set to true by default. Local storage is only created when the flag is enabled.
  • If a customer sets personalizationStorageEnabled to false at some point, local storage is cleared.
  • consent can have three states: in, out, pending
  • when personalizationStorageEnabled is true and consent is in, in that case local storage is setup once the consent is resolved.
  • in the case of defaultConsent set to out, await consent promise is not resolved & the promise falls into catch block, where we clear the local storage if it existed before.
  • in the case of defaultConsent set to pending, sendEvents calls are queued up and processed only when opted-in

Future work :

  • will add additional test with functional tests in the same PR

Related Issue

Motivation and Context

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Improvement (non-breaking change which does not add functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have signed the Adobe Open Source CLA or I'm an Adobe employee.
  • I have made any necessary test changes and all tests pass.
  • I have run the Sandbox successfully.

@shandilya3 shandilya3 changed the title Storage flag Consent & local storage config flag Oct 24, 2023
consent
}) => {
const { orgId, personalizationStorageEnabled } = config;
const eventContext = createEventContext();
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure we need the eventContext object. I see what you are trying to accomplish here, but i'd like to encapsulate the logic for event persistence within the eventRegistry as much as possible. It can manage event persistence without introducing another layer of abstraction above it.

The createEventRegistry method takes a storage parameter, this parameter specifies what to use for storage. What if we create a new function createInMemoryStorage() that provides a lean implementation of getItem and setItem where events are only stored in memory. This would be better than nothing, if the user opts out of consent or the customer disabled personalizationStorage.

// on initialization
const eventRegistry = createEventRegistry({ storage: createInMemoryStorage() })

Once the consent promise resolves, if the user opted in, you can set a new storage on the event registry.

eventRegistry.setStorage(storage.persistent); // this method doesn't exist yet, you'd need to add it. 

☝️ this would effectively tell eventRegistry to switch from in memory storage to local storage.

.catch(() => {
// If consent is rejected, we want to clear the local storage.
if (storage) {
storage.persistent.clear();
Copy link
Collaborator

Choose a reason for hiding this comment

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

If a customer sets personalizationStorageEnabled to false at some point, local storage should also be cleared. That way customer's won't disable it and wonder why they still see an entry in local storage.

const storage = createNamespacedStorage(
`${sanitizeOrgIdForCookieName(orgId)}.decisioning.`
);
consent
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it's fine to have .awaitConsent() here in the index.js file. But I wonder if it makes sense to move the listener within eventRegistry instead? 🤔 There are pros/cons.

};

const setCurrentEventRegistry = eventRegistry => {
currentEventRegistry = eventRegistry;
Copy link
Contributor

@carterworks carterworks Oct 24, 2023

Choose a reason for hiding this comment

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

If a new event registry is set, should it copy over the event history from the previous registry?

# Conflicts:
#	src/components/DecisioningEngine/createEventRegistry.js
Copy link
Collaborator

@jasonwaters jasonwaters left a comment

Choose a reason for hiding this comment

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

looks great @shandilya3 ! Just one suggestion.

@@ -132,5 +139,16 @@ export default ({ storage }) => {
return events[eventType][eventId];
};

return { addExperienceEdgeEvent, addEvent, getEvent, toJSON: () => events };
const setStorage = newStorage => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it's redundant to have both updateStorage and setStorage functions.

I recommend removing this version of setStorage and renaming the updateStorage method above to setStorage. Implementation of setStorage can be modified to accept newStorage for example...

  let currentStorage;
  let restore;
  let save;
  let events;

  const setStorage = newStorage => {
    currentStorage = newStorage;

    restore = createRestoreStorage(currentStorage, STORAGE_KEY);
    save = createSaveStorage(
      currentStorage,
      STORAGE_KEY,
      createEventPruner(MAX_EVENT_RECORDS, RETENTION_PERIOD)
    );
    events = restore({});
  };

  setStorage(storage);

@shandilya3 shandilya3 merged commit 121c8c2 into in-browser-messages Oct 25, 2023
1 check passed
@shandilya3 shandilya3 deleted the storageFlag branch October 25, 2023 22:44
jasonwaters added a commit that referenced this pull request Oct 27, 2023
* messaging action modules

* banner test

* modal test

* decisioning engine component

* fix test

* removed modulesProvider and refactored it into actionsProvider with an executeAction method

* license headers

* license headers

* introduced context provider for managing context

* license header

* introduced context provider for managing context

* license header

* message feed POC

* added some tests.

* track display/interact events and save to storage

* limit event storage

* store decision history as object

* decisioning.qualifiedItem event

* refactor event registry a little

* provide collect function to messaging actions

* fix package-lock.json

* fix debounce test

* applyResponse initialized once

* CJM-45417-globalDecisionContext (#986)

* Setting global decisionContext with data like current date/time, date/time page loaded, browser name/version, scroll position, etc

* update time and window context on each getContext call, parse url using lib
Todo: fix unit tests, add more tests and flattenObject

* dependency

* code refactoring based on code review

* add-license

* include the package-lock.json file in the pull request

* pass in userAgent in custom window object

* mock to ensure that the date remains the same across different timezones

* flattening the context object so that rules can apply

* test to check if flattening is applied and rules conditions are met for onDecision with propositions to be called

* applied fix

* a little structured tests

* following convention

* evaluates global contexts

* tests breakdown

* tests

* test global context separately

* context flattened

* mocking time, Jasmine clock does not inherently take into account different time zones

* reverted  redundant tests from other files

* flattenObject only needs to be called once.

* narrowed the scope of the test for specificity

* Revert "narrowed the scope of the test for specificity"

This reverts commit 3939b61.

* narrowed the scope of the test for specificity

* extracted reused methods

* unit test for renderDecisions command

* add license

* run for all the browser with renderDecisions

* validate a global context with command

* validate a global context with command

* always index rulesets

---------

Co-authored-by: Jason Waters <[email protected]>

* don't flatten events on context

* [CJM-48525]Renamed renderDecision command to evaluateRulesets (#994)

* renamed renderDecision to evaluateRulesets

* renamed renderDecision to evaluateRulesets fix typo

* evaluateRulesets

* added consequence adapter and refactored iframe display code

* license

* [CJM-48522]Purge historical events post retention period (#997)

* purge historical events post retention period

* fixed fragile test

* defensively check for ruleset items

* update to schema based actions

* update schemas

* rename json-ruleset-item to ruleset-item

* rename in-app message schema

* Dismiss Messages & url click (#1024)

* Ui parameter bug fix
Added Nonce to script

* better styling

* demo ready

* sandbox demo

* added unit test for buildStyleFromParameters

* unit test

* remove existing modal and overlay before displaying

* remove existing modal and overlay before displaying

* url click

* test

* clean up dom

* more test

* renamed to InAppMessages for sandbox demo

* code refactoring based on review comments

* test for script tag nonce

* transformPayload removed from alloy sandbox, it is taken care on the backend side

* test fix

---------

Co-authored-by: Jason Waters <[email protected]>

* rename qualified event to decisioning.propositionQualified

* fix test

* subscribeRulesetItems command

* license

* remove IAM types, add message feed actions modules

* license

* ensure schema based ruleset consequences

* message feed sandbox (#1028)

* message feed sandbox

* fixed eslint for InApp demo

* clear local storage and reload the page

* support "Send data to platform" trigger (#1030)

* [CJM-46521] Send interact events when in-app messages are clicked (#1031)

* Send interact events when in-app messages are clicked

* update sandbox

* evaluateRulesetsCommand (#1033)

* functional tests (#1034)

* tests

* to debug issue in sauce lab

* rephrased

* clean up

* web parameters support (#1035)

* web parameters support
removed redundant files & some clean up

* code refactoring

* adding test for web parameteres

* code refactoring based on review

* webProperties (#1039)

* webProperties

* webProperties

* improve isValidWebParameters

---------

Co-authored-by: Jason Waters <[email protected]>
Co-authored-by: Jason Waters <[email protected]>

* support "~timestampu" and  "~timestampz" (#1044)

* support "~imestampu" and  "~timestampz"

* support ~sdkver - the current Adobe Experience Platform SDKs version string.

* use existing libraryVersion

* keeping package-lock.json untouched.

* In browser messages e2e (#1045)

* updated demo to use web IAM campaign on stage

* fixed header

* update adapters for latest schema based items

* add custom trait to demo page

* allow choose environment

* resolve config warning on iam demo page

* support manual triggers

* remove surface designation on IAM sandbox demo

* clear cookies when switching demo environment

* Historical events fix (#1051)

* save payloads based on activityId

* CJM-53824

* right keys for the day and hour

* corrected payload

* npm link to local rule engine, will change to the deployed version before merging

* saved by activityId in the local storage

* constants shared between the two components src/constants

* using v2.0.2 of ruleEngine to support historical search

* fix for click through (#1054)

* Code Review Fixes  (#1052)

* use existing Alloy DOM utils

* removed unused utils method

* renamed to "test:unit:debug"

* added a try/catch to  handle potential JSON parsing errors

* removed ensureSchemaBasedRulesetConsequences

* using shorthand object property notation

* new line

* constants shared between components moved to the shared src/constants module

* use alloy utils method includes

* use alloy utils method values, objectOf

* lint

* removeElementById for readability

---------

Co-authored-by: Jason Waters <[email protected]>

* IAM: support multiple subscriptions (#1059)

* support multi-subscription

* support multi-subscription

* remove mobile app fudge

* support distinct emissions for each subscription with conditions

* event.hasQuery()

* values()

* rename mobile events

* Consent & local storage config flag (#1064)

* config flag to enable storage in localStorage

* based on consent set event registry

* tests

* for sandbox testing

* fix after test

* in-memory storage

* tests

* utils tests

* use setStorage only

---------

Co-authored-by: Jason Waters <[email protected]>

* remove message-feed (#1065)

* Move decisionContext within personalization (#1068)

* few test (#1067)

* few test

* few test

* few test

* fix test

* code review fix (#1069)

* using selectNodes, isNonEmptyArray, isNonEmptyString utils

* using toArray

* using createRedirect

* using warning instead of error

* some fixes (#1071)

* remove ALLOY from constants

---------

Co-authored-by: Happy Shandilya <[email protected]>
jasonwaters added a commit that referenced this pull request Aug 5, 2024
…uleSetItem (#1125)

* messaging action modules

* banner test

* modal test

* decisioning engine component

* fix test

* removed modulesProvider and refactored it into actionsProvider with an executeAction method

* license headers

* license headers

* introduced context provider for managing context

* license header

* introduced context provider for managing context

* license header

* message feed POC

* added some tests.

* track display/interact events and save to storage

* limit event storage

* store decision history as object

* decisioning.qualifiedItem event

* refactor event registry a little

* provide collect function to messaging actions

* fix package-lock.json

* fix debounce test

* applyResponse initialized once

* CJM-45417-globalDecisionContext (#986)

* Setting global decisionContext with data like current date/time, date/time page loaded, browser name/version, scroll position, etc

* update time and window context on each getContext call, parse url using lib
Todo: fix unit tests, add more tests and flattenObject

* dependency

* code refactoring based on code review

* add-license

* include the package-lock.json file in the pull request

* pass in userAgent in custom window object

* mock to ensure that the date remains the same across different timezones

* flattening the context object so that rules can apply

* test to check if flattening is applied and rules conditions are met for onDecision with propositions to be called

* applied fix

* a little structured tests

* following convention

* evaluates global contexts

* tests breakdown

* tests

* test global context separately

* context flattened

* mocking time, Jasmine clock does not inherently take into account different time zones

* reverted  redundant tests from other files

* flattenObject only needs to be called once.

* narrowed the scope of the test for specificity

* Revert "narrowed the scope of the test for specificity"

This reverts commit 3939b61.

* narrowed the scope of the test for specificity

* extracted reused methods

* unit test for renderDecisions command

* add license

* run for all the browser with renderDecisions

* validate a global context with command

* validate a global context with command

* always index rulesets

---------

Co-authored-by: Jason Waters <[email protected]>

* don't flatten events on context

* [CJM-48525]Renamed renderDecision command to evaluateRulesets (#994)

* renamed renderDecision to evaluateRulesets

* renamed renderDecision to evaluateRulesets fix typo

* evaluateRulesets

* added consequence adapter and refactored iframe display code

* license

* [CJM-48522]Purge historical events post retention period (#997)

* purge historical events post retention period

* fixed fragile test

* defensively check for ruleset items

* update to schema based actions

* update schemas

* rename json-ruleset-item to ruleset-item

* rename in-app message schema

* Dismiss Messages & url click (#1024)

* Ui parameter bug fix
Added Nonce to script

* better styling

* demo ready

* sandbox demo

* added unit test for buildStyleFromParameters

* unit test

* remove existing modal and overlay before displaying

* remove existing modal and overlay before displaying

* url click

* test

* clean up dom

* more test

* renamed to InAppMessages for sandbox demo

* code refactoring based on review comments

* test for script tag nonce

* transformPayload removed from alloy sandbox, it is taken care on the backend side

* test fix

---------

Co-authored-by: Jason Waters <[email protected]>

* rename qualified event to decisioning.propositionQualified

* fix test

* subscribeRulesetItems command

* license

* remove IAM types, add message feed actions modules

* license

* ensure schema based ruleset consequences

* message feed sandbox (#1028)

* message feed sandbox

* fixed eslint for InApp demo

* clear local storage and reload the page

* support "Send data to platform" trigger (#1030)

* [CJM-46521] Send interact events when in-app messages are clicked (#1031)

* Send interact events when in-app messages are clicked

* update sandbox

* evaluateRulesetsCommand (#1033)

* functional tests (#1034)

* tests

* to debug issue in sauce lab

* rephrased

* clean up

* web parameters support (#1035)

* web parameters support
removed redundant files & some clean up

* code refactoring

* adding test for web parameteres

* code refactoring based on review

* webProperties (#1039)

* webProperties

* webProperties

* improve isValidWebParameters

---------

Co-authored-by: Jason Waters <[email protected]>
Co-authored-by: Jason Waters <[email protected]>

* support "~timestampu" and  "~timestampz" (#1044)

* support "~imestampu" and  "~timestampz"

* support ~sdkver - the current Adobe Experience Platform SDKs version string.

* use existing libraryVersion

* keeping package-lock.json untouched.

* In browser messages e2e (#1045)

* updated demo to use web IAM campaign on stage

* fixed header

* update adapters for latest schema based items

* add custom trait to demo page

* allow choose environment

* resolve config warning on iam demo page

* support manual triggers

* remove surface designation on IAM sandbox demo

* clear cookies when switching demo environment

* Historical events fix (#1051)

* save payloads based on activityId

* CJM-53824

* right keys for the day and hour

* corrected payload

* npm link to local rule engine, will change to the deployed version before merging

* saved by activityId in the local storage

* constants shared between the two components src/constants

* using v2.0.2 of ruleEngine to support historical search

* fix for click through (#1054)

* Code Review Fixes  (#1052)

* use existing Alloy DOM utils

* removed unused utils method

* renamed to "test:unit:debug"

* added a try/catch to  handle potential JSON parsing errors

* removed ensureSchemaBasedRulesetConsequences

* using shorthand object property notation

* new line

* constants shared between components moved to the shared src/constants module

* use alloy utils method includes

* use alloy utils method values, objectOf

* lint

* removeElementById for readability

---------

Co-authored-by: Jason Waters <[email protected]>

* IAM: support multiple subscriptions (#1059)

* support multi-subscription

* support multi-subscription

* remove mobile app fudge

* support distinct emissions for each subscription with conditions

* event.hasQuery()

* values()

* rename mobile events

* Consent & local storage config flag (#1064)

* config flag to enable storage in localStorage

* based on consent set event registry

* tests

* for sandbox testing

* fix after test

* in-memory storage

* tests

* utils tests

* use setStorage only

---------

Co-authored-by: Jason Waters <[email protected]>

* remove message-feed (#1065)

* Revert "remove message-feed (#1065)"

This reverts commit b5a39e0.

* demo assets

* fix Message Feed

* add dismiss to message feed

* feed items from edge on sandbox

* emit previously qualified feed items at time of subscribe

* buffer propositions for subscribeRulesetItems too

* rename to content cards

* functional test

* test tweak

* remove subscribeContentCards

* house cleaning

---------

Co-authored-by: Happy Shandilya <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants