Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

Commit

Permalink
Add useDefaultCategories insted of dstinaton on ConsentManagerBuilder (
Browse files Browse the repository at this point in the history
  • Loading branch information
edsonjab committed Aug 9, 2023
1 parent 0670b5f commit 31480a2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,7 @@ export default function() {
- [cookieDomain](#cookiedomain-1)
- [shouldReload](#shouldReload-1)
- [devMode](#devMode-1)
- [useDefaultCategories](#useDefaultCategories-1)

##### children

Expand Down Expand Up @@ -793,6 +794,13 @@ Reload the page if the trackers have already been initialized so that the user's
Disable the analitics.load to make local testing.
##### useDefaultCategories
**Type**: `boolean`
**Default**: `false`
Use default categories set by Consent Manager instead of detinations.
#### ConsentManagerBuilder Render Props
- [destinations](#destinations)
Expand Down
30 changes: 25 additions & 5 deletions src/consent-manager-builder/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ interface Props {
* Disable the analitics.load to make local testing.
*/
devMode?: boolean

/**
* Default false
* Use default categories set by Consent Manager instead of detinations
*/
useDefaultCategories?: boolean
}

interface RenderProps {
Expand Down Expand Up @@ -129,6 +135,13 @@ interface State {
workspaceAddedNewDestinations: boolean
}

const DEFAULT_CATEGORIES = {
functional: false,
marketingAndAnalytics: false,
advertising: false,
essential: false
}

export default class ConsentManagerBuilder extends Component<Props, State> {
static displayName = 'ConsentManagerBuilder'

Expand All @@ -139,7 +152,8 @@ export default class ConsentManagerBuilder extends Component<Props, State> {
initialPreferences: {},
cdnHost: 'cdn.segment.com',
shouldReload: true,
devMode: false
devMode: false,
useDefaultCategories: false
}

state = {
Expand All @@ -150,7 +164,8 @@ export default class ConsentManagerBuilder extends Component<Props, State> {
destinationPreferences: {},
isConsentRequired: true,
havePreferencesChanged: false,
workspaceAddedNewDestinations: false
workspaceAddedNewDestinations: false,
useDefaultCategories: false
}

render() {
Expand Down Expand Up @@ -208,7 +223,8 @@ export default class ConsentManagerBuilder extends Component<Props, State> {
cookieName,
cdnHost = ConsentManagerBuilder.defaultProps.cdnHost,
shouldReload = ConsentManagerBuilder.defaultProps.shouldReload,
devMode = ConsentManagerBuilder.defaultProps.devMode
devMode = ConsentManagerBuilder.defaultProps.devMode,
useDefaultCategories = ConsentManagerBuilder.defaultProps.useDefaultCategories
} = this.props

// TODO: add option to run mapCustomPreferences on load so that the destination preferences automatically get updated
Expand All @@ -232,7 +248,9 @@ export default class ConsentManagerBuilder extends Component<Props, State> {
)

if (mapCustomPreferences) {
preferences = customPreferences || initialPreferences || {}
preferences = useDefaultCategories
? DEFAULT_CATEGORIES
: customPreferences || initialPreferences || {}
if (
(initialPrefencesHaveValue && emptyCustomPreferecences) ||
(defaultDestinationBehavior === 'imply' && workspaceAddedNewDestinations)
Expand All @@ -243,7 +261,9 @@ export default class ConsentManagerBuilder extends Component<Props, State> {
preferences = customPreferences
}
} else {
preferences = destinationPreferences || initialPreferences
preferences = useDefaultCategories
? DEFAULT_CATEGORIES
: destinationPreferences || initialPreferences
}

conditionallyLoadAnalytics({
Expand Down

0 comments on commit 31480a2

Please sign in to comment.