OneCX Consent
Overview
The Consent component (<ocx-consent>) gates projected content behind explicit user consent.
Typical GDPR/ePrivacy use cases include embedding third-party resources (maps, analytics, videos) where no network requests should happen before opt-in.
Usage
Import the AngularAcceleratorModule and use the component in your template.
<ocx-consent
[url]="tileServerUrl"
purpose="maps"
[showWithdraw]="true"
>
<a ocx-consent-info href="/privacy">Privacy policy</a>
<!-- Rendered only when consent exists. -->
<app-leaflet-map [tileUrl]="tileServerUrl" />
</ocx-consent>
| Angular projected content is created in the host component’s view. If your projected content is an Angular component that performs side effects on creation (e.g. network requests in constructors/effects), you should still guard its instantiation. |
One simple pattern is to toggle an *ngIf (or @if) based on the consentChanged output:
<ocx-consent
[url]="tileServerUrl"
purpose="maps"
(consentChanged)="mapConsentGranted = $event.hasConsent"
>
<app-leaflet-map *ngIf="mapConsentGranted" [tileUrl]="tileServerUrl" />
</ocx-consent>
Content projection
The component supports two projection areas:
-
Default projection: the gated content that is only rendered after consent is present.
-
[ocx-consent-info]: optional informational content shown in the consent prompt (e.g. provider name, privacy policy link).
Inputs
| Input name | Type | Default | Description |
|---|---|---|---|
|
|
- |
Required. Target URL that the gated content will contact (used for display and consent matching). |
|
|
- |
Optional scope for consent (e.g. |
|
|
|
Translation key for the consent title. |
|
|
|
Translation key for the consent message (receives |
|
|
|
Translation key for the agree button. |
|
|
|
Translation key for the withdraw button. |
|
|
|
When enabled, shows a withdraw button that removes the stored consent. |
Outputs
| Output name | Type | Description |
|---|---|---|
|
Emits whenever consent is granted or withdrawn. |
Storage and matching
Consent is stored in the browser using localStorage:
-
Key:
onecx-consent -
Format: JSON string array
-
Entries: either
<normalizedUrl>or<normalizedUrl>::<purpose>
URL normalization aims to avoid accidental mismatches:
-
Trims whitespace
-
Removes
#hashand?query -
Lowercases the hostname
-
Removes a trailing slash
If url is not parseable as a URL, a trimmed string with a trailing slash removed is used.