Skip to content

Commit

Permalink
Merge pull request #59 from AzureCosmosDB/v-deagau/consent-details
Browse files Browse the repository at this point in the history
1DS Consent Details
  • Loading branch information
jaydestro authored May 2, 2024
2 parents 8c193a7 + 7c3f599 commit c7ce232
Showing 1 changed file with 63 additions and 18 deletions.
81 changes: 63 additions & 18 deletions scripts/1ds.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
// 1DS initialization
// 1DS initialization.
const analytics = new oneDS.ApplicationInsights();
var config = {
instrumentationKey: "df7baf4530c843e3aa2af4b0772d887e-437761a3-5b14-45c1-a6ed-742c832d01b1-7030",
propertyConfiguration: { // Properties Plugin configuration
gpcDataSharingOptIn: false,
propertyConfiguration: { // Properties Plugin configuration.
// Set with the CCPA gpcDataSharingOptIn property to GPC_DataSharingOptIn. UHF handles both GPC (browser) and AMC (MS account)
// in GPC_DataSharingOptIn global variable. Page refresh will show if CCPA was updated. No callback is currently available.
//gpcDataSharingOptIn: GPC_DataSharingOptIn,
gpcDataSharingOptIn: false, // Due to cross domain issue, it is always false for this project.
callback: {
// Set userConsentDetails callback when global siteConsent variable is available, after consent banner is initialized in UHF.
userConsentDetails: undefined
},
},
webAnalyticsConfiguration: { // Web Analytics Plugin configuration
coreData: {
Expand All @@ -17,30 +24,68 @@ var config = {
resize: true,
jsError: true,
},
urlCollectQuery: true, // The default is false, hence very Important
urlCollectHash: true, // The default is false, hence very Important
useShortNameForContentBlob: true // The default is true
urlCollectQuery: true, // The default is false, hence very Important.
urlCollectHash: true, // The default is false, hence very Important.
useShortNameForContentBlob: true // The default is true.
}
};
try {
config.webAnalyticsConfiguration.coreData.pageName = pageName;
} catch (e) {
// if that didn't work, just don't set pageName so it will fall back to default.
// If that didn't work, just don't set pageName so it will fall back to default.
}

//Initialize SDK
analytics.initialize(config, []);
// Callback for onInitCallback event triggered by the consent banner initialization via UHF.
function onInitCallback(categoryPreferences) {
console.log("onInitCallback", categoryPreferences);

// Set callback for userConsentDetails.
config.propertyConfiguration.callback.userConsentDetails = siteConsent ? siteConsent.getConsent : undefined;

//Initialize 1DS SDK.
analytics.initialize(config, []);

handleConsentPreferences(categoryPreferences);
}

// Register for onConsentChanged event triggered by the consent banner.
// Callback for onConsentChanged event triggered by a consent banner update via UHF.
function onConsentChanged(categoryPreferences) {
console.log("onConsentChanged", categoryPreferences);
console.log("categoryPreferences.Required", categoryPreferences.Required);
console.log("categoryPreferences.Analytics", categoryPreferences.Analytics);
console.log("categoryPreferences.Advertising", categoryPreferences.Advertising);
console.log("categoryPreferences.SocialMedia", categoryPreferences.SocialMedia);
handleConsentPreferences(categoryPreferences);
}

// For GitHub, all these values (except required) are false regardless of what cookie banner sets. Most likely due to cross domain.
//analytics.getPropertyManager().getPropertiesContext().web.gpcDataSharingOptIn = categoryPreferences.Analytics;
};
function handleConsentPreferences(categoryPreferences) {
// Block or enable the writing and reading of all third-party Optional/Non-essential cookies. These equate to cookies with categories 3A, 3B, and 3C
// that have non-Microsoft owned domains. Accomplished by blocking/enabling 3rd party pixels, scripts, tags, and beacons before they fire.

// The "GPC_DataSharingOptIn" was specifically added for CCPA and not specifically for EUCC compliance so it shouldn't really be set here.
// If it needs to be set after analytics initialization use analytics.getPropertyManager().getPropertiesContext().web.gpcDataSharingOptIn = true;

WcpConsent.onConsentChanged(onConsentChanged);
// Catalysis typically does not deal with categoryPreferences.Advertising and categoryPreferences.SocialMedia so nothing to do with those.

// QUESTION ON ANALYTICS (1DS)
// 1DS is categoryPreferences.Analytics. Anything we need to do special for this for true/false? Already setting config callback for details in 1DS payload.
// Is that sufficient for tagging 1st party data to stop use downstream for 1DS?

// Don't know if this actually works or not.
// By default, the 1DS JS SDK does not collect or write non-essential cookies. However, adopters have the option to turn on the collection of some
// non-essential cookies (e.g., MicrosoftApplicationsTelemetryDeviceId) which requires user consent. This can be done by turning off the
// config.disableCookiesUsage setting (set value to true).

// if (categoryPreferences.Analytics) {
// // If not already enabled, do so here.
// } else {
// // If not already disabled, do so here.
// }
}

if (WcpConsent) {
// Set consent callbacks.
WcpConsent.onInitCallback(onInitCallback);
WcpConsent.onConsentChanged(onConsentChanged);
} else {
console.log("No consent banner so no 1DS initialization.");

// Assuming siteConsent would also not be defined.
// analytics.initialize(config, []);
}

0 comments on commit c7ce232

Please sign in to comment.