Skip to content

Commit fbbb1d3

Browse files
authored
Include vendors disclosed segment in TC string for __tcfapi (#7266)
1 parent ccd339e commit fbbb1d3

File tree

3 files changed

+41
-13
lines changed

3 files changed

+41
-13
lines changed

changelog/7266.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
description: Included vendors disclosed segment in TC string for __tcfapi getTCData
2+
type: Fixed
3+
pr: 7266
Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import { FidesEvent } from "../events";
2-
import { FIDES_SEPARATOR } from "./constants";
2+
import { decodeFidesString } from "../fides-string";
33

44
/**
5-
* Extract just the TC string from a FidesEvent. This will also remove parts of the
6-
* TC string that we do not want to surface with our CMP API events, such as
7-
* `vendors_disclosed` and our own AC string addition.
5+
* Extract just the TC string from a FidesEvent.
86
*
97
* Returns a string to be used for the `CmpApi` class from `@iabtechlabtcf/cmpapi`, which expects one of three input strings:
108
* - Encoded TC string (e.g. "CP1sGZVP1..."), which will be decoded into `TCData` and set `gdprApplies = true`
@@ -23,14 +21,9 @@ export const extractTCStringForCmpApi = (event: FidesEvent): string | null => {
2321
return null;
2422
}
2523
const { fides_string: cookieString } = event.detail;
26-
if (cookieString) {
27-
// Remove the AC portion which is separated by FIDES_SEPARATOR
28-
const [tcString] = cookieString.split(FIDES_SEPARATOR);
29-
// We only want to return the first part of the tcString, which is separated by '.'
30-
// This means Publisher TC is not sent either, which is okay for now since we do not set it.
31-
// However, if we do one day set it, we would have to decode the string and encode it again
32-
// without vendorsDisclosed
33-
return tcString.split(".")[0];
24+
if (!cookieString) {
25+
return "";
3426
}
35-
return cookieString ?? "";
27+
const { tc } = decodeFidesString(cookieString);
28+
return tc ?? "";
3629
};

clients/privacy-center/cypress/e2e/fides-js/consent-banner-tcf.cy.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3918,6 +3918,38 @@ describe("Fides-js TCF", () => {
39183918
});
39193919
});
39203920

3921+
it("TC string from __tcfapi matches the TC portion of Fides.fides_string", () => {
3922+
cy.get("#fides-tab-vendors").click();
3923+
cy.getByTestId("consent-modal").within(() => {
3924+
cy.get("button").contains("Opt in to all").click();
3925+
});
3926+
cy.wait("@patchPrivacyPreference");
3927+
3928+
cy.window().then((win) => {
3929+
win.__tcfapi("getTCData", 2, cy.stub().as("getTCData"));
3930+
cy.get("@getTCData")
3931+
.should("have.been.calledOnce")
3932+
.its("lastCall.args")
3933+
.then(([tcData, success]) => {
3934+
expect(success).to.eql(true);
3935+
3936+
// Get TC string from __tcfapi
3937+
const tcStringFromApi = tcData.tcString;
3938+
3939+
// Get TC string from fides_string (before the FIDES_SEPARATOR)
3940+
const fidesStringFull = win.Fides.fides_string;
3941+
const [tcStringFromFides] = fidesStringFull.split(FIDES_SEPARATOR);
3942+
3943+
// They should match exactly, including disclosed vendors segment
3944+
expect(tcStringFromApi).to.eql(tcStringFromFides);
3945+
3946+
// Both should include the disclosed vendors segment (indicated by a '.')
3947+
expect(tcStringFromApi).to.contain(".");
3948+
expect(tcStringFromFides).to.contain(".");
3949+
});
3950+
});
3951+
});
3952+
39213953
it("can get `addtlConsents` from getTCData custom function", () => {
39223954
cy.get("#fides-tab-vendors").click();
39233955
cy.getByTestId("consent-modal").within(() => {

0 commit comments

Comments
 (0)