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

Updates GTM datalayer to include all documented details, includes consentMethod in all fides events where applicable #4847

Merged
merged 12 commits into from
May 3, 2024

Conversation

eastandwestwind
Copy link
Contributor

@eastandwestwind eastandwestwind commented Apr 30, 2024

Closes https://ethyca.atlassian.net/browse/PROD-2006

Description Of Changes

  • Updates GTM datalayer to include all details documented in our docs

  • Includes consentMethod in all fides events where applicable

Code Changes

  • Pushes additional properties to the datalayer in our GTM helper
  • Update core Fides event helper to build consentMethod details off the cookie
  • Add tests

Steps to Confirm

Screenshot 2024-04-30 at 6 05 58 PM

Pre-Merge Checklist

Copy link

vercel bot commented Apr 30, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
fides-plus-nightly ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 3, 2024 4:27pm

Copy link

cypress bot commented Apr 30, 2024

Passing run #7606 ↗︎

0 4 0 0 Flakiness 0

Details:

Merge 3097615 into 221cb05...
Project: fides Commit: fce085dd0f ℹ️
Status: Passed Duration: 00:35 💡
Started: May 3, 2024 4:37 PM Ended: May 3, 2024 4:38 PM

Review all test suite changes for PR #4847 ↗︎

},
});

// TODO- right now we have to use a wait before our cy.waitUntilFidesInitialized() call which is flakey in CI
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we saw a cy.wait working locally, but in CI this sometimes works and sometimes doesn't

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't really like lingering TODOs like this... I'd prefer you delete this commented out block entirely TBH, the GTM events are pretty well exercised elsewhere.

cy.get("@dataLayerPush")
.its("secondCall.args.0")
.its("Fides.fides_string")
.should("contain", ",1~");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

partial match and not as part of the assertion on line 681 above, because the fides_string generated is inconsistent

Copy link
Contributor

@NevilleS NevilleS left a comment

Choose a reason for hiding this comment

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

This looks pretty solid, a few tweaks here and I think there might be a surprise bug in the FidesInitialized event fired by the getInitialFides part of the code...

interface FidesVariable {
consent: NoticeConsent;
}
type FidesVariable = FidesEvent["detail"];
Copy link
Contributor

Choose a reason for hiding this comment

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

✨ I'm glad this worked

@@ -174,6 +174,7 @@ export type FidesJSIdentity = Record<string, string>;
* {
* "version": "0.9.0",
* "createdAt": "2023-01-01T12:00:00.000Z",
* "consentMethod": "accept",
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice 👍

@@ -79,6 +79,7 @@ const ConfigDrivenConsent = ({
};
});
const cookie: FidesCookie = getOrMakeFidesCookie();
cookie.fides_meta.consentMethod = ConsentMethod.SAVE; // include the consentMethod as extra metadata
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, interesting, yes this makes sense too... good eye.

@@ -325,9 +331,32 @@ describe("Consent settings", () => {
analytics: true,
gpc_test: true,
},
extraDetails: undefined,
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm- why is this? Shouldn't the cookie include consentMethod: "save" (your test above asserts that)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hm weird. The 2nd init is being populated correctly with "save" but the 1st init is not, and currently trying to debug

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Logging it right before we 1st call FidesInitalized is showing up fine with save:

 console.log(cookie.fides_meta.consentMethod)
 dispatchFidesEvent("FidesInitialized", cookie, config.options.debug);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the event log is even looking good, it's just not making it into the dataLayer:

Dispatching event type FidesInitialized with cookie {"consent":{"data_sales":false,"tracking":false,"analytics":true,"gpc_test":true},"identity":{"fides_user_device_id":"9ccb17a8-4104-4968-81a7-db5004350c97"},"fides_meta":{"version":"0.9.0","createdAt":"2024-05-02T10:52:43.981Z","updatedAt":"2024-05-02T10:52:44.367Z","consentMethod":"save"},"tcf_consent":{}} using consent method save 

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Solved- turns out we have to keep window.Fides in sync more often because Fides.gtm() sometimes runs after the init events. In this case we fire a synthetic event that depends on props off of window.Fides. I've additionally updated our test sites to run Fides.gtm() earlier.

},
});

// TODO- right now we have to use a wait before our cy.waitUntilFidesInitialized() call which is flakey in CI
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't really like lingering TODOs like this... I'd prefer you delete this commented out block entirely TBH, the GTM events are pretty well exercised elsewhere.

clients/fides-js/src/lib/events.ts Show resolved Hide resolved
clients/fides-js/src/lib/events.ts Show resolved Hide resolved
@@ -117,6 +123,7 @@ async function init(this: FidesGlobal, config: FidesConfig) {
});
if (initialFides) {
Object.assign(this, initialFides);
updateWindowFides(this);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Our synthetic GTM event (https://github.com/ethyca/fides/pull/4847/files#diff-a04bb0647e72a17425850d5589eee0a2f72b4f239a0d721899cd15029555be6aR62) requires window.Fides to contain up-to-date properties

Copy link
Contributor

Choose a reason for hiding this comment

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

This is such a subtle footgun! Gah, the state mgmt in FidesJS has a lot of footguns

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agreed. This is the flakiest part of FidesJS

Copy link
Contributor

@NevilleS NevilleS left a comment

Choose a reason for hiding this comment

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

Awesome, thanks!

@@ -117,6 +123,7 @@ async function init(this: FidesGlobal, config: FidesConfig) {
});
if (initialFides) {
Object.assign(this, initialFides);
updateWindowFides(this);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is such a subtle footgun! Gah, the state mgmt in FidesJS has a lot of footguns

@eastandwestwind eastandwestwind merged commit bd9f752 into main May 3, 2024
13 checks passed
@eastandwestwind eastandwestwind deleted the PROD-2006 branch May 3, 2024 16:40
Kelsey-Ethyca pushed a commit that referenced this pull request May 3, 2024
…sentMethod in all fides events where applicable (#4847)
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.

2 participants