-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c823e6f
commit b90025b
Showing
5 changed files
with
719 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
var googleConsentValues = { | ||
// Server Integration uses 'Unspecified' as a value when the setting is 'not set'. | ||
// However, this is not used by Google's Web SDK. We are referencing it here as a comment | ||
// as a record of this distinction and for posterity. | ||
// If Google ever adds this for web, the line can just be uncommented to support this. | ||
// | ||
// Docs: | ||
// Web: https://developers.google.com/tag-platform/gtagjs/reference#consent | ||
// S2S: https://developers.google.com/google-ads/api/reference/rpc/v15/ConsentStatusEnum.ConsentStatus | ||
// | ||
// Unspecified: 'unspecified', | ||
Denied: 'denied', | ||
Granted: 'granted', | ||
}; | ||
|
||
var googleConsentProperties = [ | ||
'ad_storage', | ||
'ad_user_data', | ||
'ad_personalization', | ||
'analytics_storage', | ||
]; | ||
|
||
function ConsentHandler(common) { | ||
this.common = common || {}; | ||
} | ||
|
||
ConsentHandler.prototype.getUserConsentState = function () { | ||
var userConsentState = null; | ||
|
||
if (mParticle.Identity && mParticle.Identity.getCurrentUser) { | ||
var currentUser = mParticle.Identity.getCurrentUser(); | ||
|
||
if (!currentUser) { | ||
return null; | ||
} | ||
|
||
var consentState = | ||
mParticle.Identity.getCurrentUser().getConsentState(); | ||
|
||
if (consentState && consentState.getGDPRConsentState) { | ||
userConsentState = consentState.getGDPRConsentState(); | ||
} | ||
} | ||
|
||
return userConsentState; | ||
}; | ||
|
||
ConsentHandler.prototype.getEventConsentState = function (eventConsentState) { | ||
return eventConsentState && eventConsentState.getGDPRConsentState | ||
? eventConsentState.getGDPRConsentState() | ||
: null; | ||
}; | ||
|
||
ConsentHandler.prototype.getConsentSettings = function () { | ||
var consentSettings = {}; | ||
|
||
var googleToMpConsentSettingsMapping = { | ||
ad_storage: 'adStorageConsentWeb', | ||
ad_user_data: 'adUserDataConsentWeb', | ||
ad_personalization: 'adPersonalizationConsentWeb', | ||
analytics_storage: 'analyticsStorageConsentWeb', | ||
}; | ||
|
||
var forwarderSettings = this.common.forwarderSettings; | ||
|
||
Object.keys(googleToMpConsentSettingsMapping).forEach(function ( | ||
googleConsentKey | ||
) { | ||
var mpConsentSettingKey = | ||
googleToMpConsentSettingsMapping[googleConsentKey]; | ||
var googleConsentValuesKey = forwarderSettings[mpConsentSettingKey]; | ||
|
||
if (googleConsentValuesKey && mpConsentSettingKey) { | ||
consentSettings[googleConsentKey] = | ||
googleConsentValues[googleConsentValuesKey]; | ||
} | ||
}); | ||
|
||
return consentSettings; | ||
}; | ||
|
||
ConsentHandler.prototype.generateConsentStatePayloadFromMappings = function ( | ||
consentState, | ||
mappings | ||
) { | ||
var payload = this.common.cloneObject(this.common.consentPayloadDefaults); | ||
|
||
for (var i = 0; i <= mappings.length - 1; i++) { | ||
var mappingEntry = mappings[i]; | ||
var mpMappedConsentName = mappingEntry.map; | ||
var googleMappedConsentName = mappingEntry.value; | ||
|
||
if ( | ||
consentState[mpMappedConsentName] && | ||
googleConsentProperties.indexOf(googleMappedConsentName) !== -1 | ||
) { | ||
payload[googleMappedConsentName] = consentState[mpMappedConsentName] | ||
.Consented | ||
? googleConsentValues.Granted | ||
: googleConsentValues.Denied; | ||
} | ||
} | ||
|
||
return payload; | ||
}; | ||
|
||
module.exports = ConsentHandler; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.