Skip to content

Commit

Permalink
When the TC String is included in GPP and Layer 1 is visible, the sig…
Browse files Browse the repository at this point in the history
…nalStatus should be "not ready" (#4957)
  • Loading branch information
gilluminate authored Jun 6, 2024
1 parent e3d8bd2 commit 806c646
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ The types of changes are:
- Fixed an issue where language form field error message was not displaying properly [#4942](https://github.com/ethyca/fides/pull/4942)
- Fixed an issue where the consent cookie could not be set on multi-level root domain (e.g. co.uk, co.jp) [#4935](https://github.com/ethyca/fides/pull/4935)
- Fixed an issue where the unique device ID was not being retained when Fides.js was reinitialized [#4947](https://github.com/ethyca/fides/pull/4947)
- Fixed an issue where the GPP signal status was prematurely set to `ready` in some scenarios [#4957](https://github.com/ethyca/fides/pull/4957)

## [2.37.0](https://github.com/ethyca/fides/compare/2.36.0...2.37.0)

Expand Down
18 changes: 12 additions & 6 deletions clients/fides-js/src/fides-ext-gpp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,18 +133,19 @@ const initializeGppCmpApi = () => {
makeStub();
const cmpApi = new CmpApi(ETHYCA_CMP_ID, CMP_VERSION);
cmpApi.setCmpStatus(CmpStatus.LOADED);
// If consent does not need to be resurfaced, then we can set the signal to Ready here
window.addEventListener("FidesInitialized", (event) => {
// TODO (PROD-1439): re-evaluate if GPP is "cheating" accessing window.Fides instead of using the event details only
const { experience, saved_consent: savedConsent } = window.Fides;
const { experience, saved_consent: savedConsent, options } = window.Fides;
const isTcfEnabled = options.tcfEnabled;
cmpApi.setSupportedAPIs(getSupportedApis());
// Set status to ready immediately upon initialization, if either:
// A. Consent should not be resurfaced
// B. User has no prefs and has all opt-in notices
// B. User has no prefs and has all opt-in notices and TCF is disabled
if (
isPrivacyExperience(experience) &&
(!shouldResurfaceConsent(experience, event.detail, savedConsent) ||
(allNoticesAreDefaultOptIn(experience.privacy_notices) &&
(!isTcfEnabled &&
allNoticesAreDefaultOptIn(experience.privacy_notices) &&
!userHasExistingPrefs(
savedConsent,
event.detail.fides_string,
Expand Down Expand Up @@ -176,10 +177,12 @@ const initializeGppCmpApi = () => {

window.addEventListener("FidesUIShown", (event) => {
// Set US GPP notice fields
const { experience, saved_consent: savedConsent } = window.Fides;
const { experience, saved_consent: savedConsent, options } = window.Fides;
const isTcfEnabled = options.tcfEnabled;
if (isPrivacyExperience(experience)) {
// set signal status to ready only for users with no existing prefs and if notices are all opt-in by default
// set signal status to ready only for users with no existing prefs and if notices are all opt-in by default and TCF is disabled
if (
!isTcfEnabled &&
allNoticesAreDefaultOptIn(experience.privacy_notices) &&
!userHasExistingPrefs(
savedConsent,
Expand All @@ -198,6 +201,9 @@ const initializeGppCmpApi = () => {
});
if (sectionsChanged.length) {
cmpApi.setApplicableSections(sectionsChanged.map((s) => s.id));
sectionsChanged.forEach((section) => {
cmpApi.fireSectionChange(section.name);
});
}
}
});
Expand Down
38 changes: 23 additions & 15 deletions clients/privacy-center/cypress/e2e/consent-banner-gpp.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe("Fides-js GPP extension", () => {
.its("lastCall.args")
.then(([data, success]) => {
expect(success).to.eql(true);
expect(data.signalStatus).to.eql("ready");
expect(data.signalStatus).to.eql("not ready");
});
});
});
Expand All @@ -114,8 +114,8 @@ describe("Fides-js GPP extension", () => {
it("fires appropriate gpp events for first time user", () => {
cy.waitUntilFidesInitialized().then(() => {
cy.get("@FidesUIShown").should("have.been.calledOnce");
// TODO(PROD#1439): Because the stub is too late right now, we can't listen for events
// 3 and 4 yet.
// TODO(PROD#1439): Because the stub is too late right now, we can't listen for events 3 and 4 yet.

cy.window().then((win) => {
win.__gpp("addEventListener", cy.stub().as("gppListener"));
});
Expand All @@ -128,7 +128,7 @@ describe("Fides-js GPP extension", () => {
expect(data.eventName).to.eql("listenerRegistered");
const { cmpDisplayStatus, signalStatus, gppString } = data.pingData;
expect(cmpDisplayStatus).to.eql("visible");
expect(signalStatus).to.eql("ready");
expect(signalStatus).to.eql("not ready");
expect(gppString).to.eql("DBAA"); // empty string, header only
});

Expand Down Expand Up @@ -193,8 +193,8 @@ describe("Fides-js GPP extension", () => {

cy.waitUntilFidesInitialized().then(() => {
cy.get("@FidesUIShown").should("not.have.been.called");
// TODO(PROD#1439): Because the stub is too late right now, we can't listen for events
// 3 and 4 yet.
// TODO(PROD#1439): Because the stub is too late right now, we can't listen for events 3 and 4 yet.

cy.window().then((win) => {
win.__gpp("addEventListener", cy.stub().as("gppListener"));
});
Expand Down Expand Up @@ -228,6 +228,7 @@ describe("Fides-js GPP extension", () => {
.its("args")
.then((args) => {
expect(args.length).to.eql(3);
// when modal opens, the signal status should be changed back to "not ready"
const expected = [
{ eventName: "signalStatus", data: "not ready" },
{ eventName: "cmpDisplayStatus", data: "visible" },
Expand Down Expand Up @@ -277,8 +278,10 @@ describe("Fides-js GPP extension", () => {
* 7. signalStatus = not ready
*/
it("can handle returning user closing the modal", () => {
const tcString = "CPziCYAPziCYAGXABBENATEIAACAAAAAAAAAABEAAAAA";
const cookie = mockCookie({
tcf_version_hash: TCF_VERSION_HASH,
fides_string: tcString,
});
cy.setCookie(CONSENT_COOKIE_NAME, JSON.stringify(cookie));
cy.fixture("consent/experience_tcf.json").then((experience) => {
Expand All @@ -296,9 +299,11 @@ describe("Fides-js GPP extension", () => {
});
cy.get("#fides-modal-link").click();
cy.get(".fides-modal-content .fides-close-button").click();

// when modal opens, the signal status should be changed back to "not ready"
const expected = [
{ eventName: "listenerRegistered", data: true },
{ eventName: "signalStatus", data: "ready" },
{ eventName: "signalStatus", data: "not ready" },
{ eventName: "cmpDisplayStatus", data: "visible" },
{ eventName: "cmpDisplayStatus", data: "hidden" },
{ eventName: "signalStatus", data: "ready" },
Expand Down Expand Up @@ -349,14 +354,9 @@ describe("Fides-js GPP extension", () => {
expect(success).to.eql(true);
expect(data.eventName).to.eql("cmpDisplayStatus");
expect(data.data).to.eql("visible");
const {
signalStatus,
gppString,
applicableSections,
supportedAPIs,
} = data.pingData;
expect(signalStatus).to.eql("ready");
expect(applicableSections).to.eql([-1]);
const { signalStatus, gppString, supportedAPIs } = data.pingData;
// when modal opens, the signal status should be changed back to "not ready"
expect(signalStatus).to.eql("not ready");
expect(supportedAPIs).to.eql([]);
expect(gppString).to.eql("DBAA");
});
Expand All @@ -383,6 +383,7 @@ describe("Fides-js GPP extension", () => {
.its("lastCall.args")
.then(([data, success]) => {
expect(success).to.eql(true);
// because TCF is disabled, status can always be "ready"
expect(data.signalStatus).to.eql("ready");
});
});
Expand Down Expand Up @@ -535,6 +536,8 @@ describe("Fides-js GPP extension", () => {
// Opt in string
expect(data.pingData.applicableSections).to.eql([8]);
expect(data.pingData.gppString).to.eql("DBABBg~BUoAAABY.QA");
// because TCF is disabled, status can always be "ready"
expect(data.pingData.signalStatus).to.eql("ready");
});
});
});
Expand Down Expand Up @@ -564,6 +567,7 @@ describe("Fides-js GPP extension", () => {
.its("lastCall.args")
.then(([data, success]) => {
expect(success).to.eql(true);
// because TCF is disabled, status can always be "ready"
expect(data.signalStatus).to.eql("ready");
expect(data.applicableSections).to.eql([-1]);
});
Expand All @@ -581,6 +585,7 @@ describe("Fides-js GPP extension", () => {
const [data, success] = args[2];
expect(success).to.eql(true);
expect(data.pingData.applicableSections).to.eql([-1]);
expect(data.pingData.signalStatus).to.eql("ready");
});
});

Expand All @@ -595,6 +600,7 @@ describe("Fides-js GPP extension", () => {
const [data, success] = args[2];
expect(success).to.eql(true);
expect(data.pingData.applicableSections).to.eql([-1]);
expect(data.pingData.signalStatus).to.eql("ready");
});
});

Expand Down Expand Up @@ -624,6 +630,8 @@ describe("Fides-js GPP extension", () => {
// Opt in string
expect(data.pingData.applicableSections).to.eql([-1]);
expect(data.pingData.gppString).to.eql("DBAA");
// because TCF is disabled, status can always be "ready"
expect(data.pingData.signalStatus).to.eql("ready");
});
});
});
Expand Down

0 comments on commit 806c646

Please sign in to comment.