Skip to content

Commit

Permalink
chore(demo-consent): Display if cookies are enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud73 committed Jul 21, 2023
1 parent b3e6cbf commit c7ea341
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
3 changes: 3 additions & 0 deletions projects/demo/src/app/consent/consent.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ <h2>User consent for tracking</h2>
If you have configured the Matomo tracker to expect consent for tracking, then no tracking will
occur until consent is given.
</p>
<p>
Is Matomo using cookies? <kbd>{{ hasCookies }}</kbd>
</p>
<footer>
<div class="grid">
<button class="primary" (click)="onGiveConsent($event)">Give Consent</button>
Expand Down
19 changes: 10 additions & 9 deletions projects/demo/src/app/consent/consent.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,29 @@ import { MatomoTracker } from 'ngx-matomo';
})
export class ConsentComponent implements OnInit {
private readonly matomoTracker = inject(MatomoTracker);
public hasCookies: boolean = false;

public readonly giveConsentCode = 'this.matomoTracker.setConsentGiven();';
public readonly removeConsentCode = 'this.matomoTracker.forgetConsentGiven();';
public readonly hasCookiesCode = 'this.matomoTracker.hasCookies().then(console.log);';

ngOnInit(): void {
this.matomoTracker
.hasCookies()
.then((hasCookies: boolean) => console.log('Has Cookies:', hasCookies));
this.matomoTracker.hasCookies().then((it) => {
this.hasCookies = it;
});
}

onGiveConsent(event: MouseEvent): void {
this.matomoTracker.setConsentGiven();
this.matomoTracker
.hasCookies()
.then((hasCookies: boolean) => console.log('Has Cookies:', hasCookies));
this.matomoTracker.hasCookies().then((it) => {
this.hasCookies = it;
});
}

onRemoveConsent(event: MouseEvent): void {
this.matomoTracker.forgetConsentGiven();
this.matomoTracker
.hasCookies()
.then((hasCookies: boolean) => console.log('Has Cookies:', hasCookies));
this.matomoTracker.hasCookies().then((it) => {
this.hasCookies = it;
});
}
}

0 comments on commit c7ea341

Please sign in to comment.