Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I opt-in a session when cookie consent is not required? #135

Open
bacongobbler opened this issue Sep 13, 2023 · 0 comments
Open

How do I opt-in a session when cookie consent is not required? #135

bacongobbler opened this issue Sep 13, 2023 · 0 comments

Comments

@bacongobbler
Copy link

bacongobbler commented Sep 13, 2023

Is your feature request related to a problem? Please describe

I do not know how to check whether the user is in a region where cookie consent is not required. I want users who are in a region where cookie consent is not required (USA) to opt-in by default, and users who are in a region where cookie consent is required (EU) to opt-out by default.

Currently, I have my cookie consent config set to something like this:

const cookieConfig: NgcCookieConsentConfig = {
  cookie: {
    domain: window.location.hostname,
  },
  type: 'opt-in',
  location: true,
};

And currently I have my app.component.ts set up like this:

import { Component, OnInit, OnDestroy } from '@angular/core';
import { NgcCookieConsentService } from 'ngx-cookieconsent';
import { Subscription }   from 'rxjs';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit, OnDestroy {

  //keep refs to subscriptions to be able to unsubscribe later
  private statusChangeSubscription!: Subscription;

  constructor(private ccService: NgcCookieConsentService){}

  ngOnInit() {

    this.statusChangeSubscription = this.ccService.statusChange$.subscribe(
      (event: NgcStatusChangeEvent) => {
        switch (event.status) {
          case 'allow':
            // when the user consents, we start collecting analytics.
            doSomething();
            break;
          case 'deny':
            // when the user declines, we stop collecting analytics.
            doSomething();
            break;
          default:
            // when the user dismisses the window, do nothing
            break;
  }

  ngOnDestroy() {
    // unsubscribe to cookieconsent observables to prevent memory leaks
    this.statusChangeSubscription.unsubscribe();
  }
}

With this logic, if the user is in a region like the US, they never "allowed" cookies, so we never start collecting analytics from the user.

Describe the idea you'd like

If the user is in a region where cookie consent law is not required, I'd like to disable the cookie consent component and opt-in the user to cookie consent. However if the user is in a region where cookie consent law is required, I'd like to enable the cookie consent component and provide them with the choice to allow or deny cookies (type: "opt-in").

Describe alternatives you've considered

Our current system does not use the location feature, which works around this issue by forcing every user to consent.

Additional context

No response

@bacongobbler bacongobbler changed the title Opt-in when cookie consent is not required, opt-out when it is required (GDPR) How do I opt-in a session when cookie consent is not required? Sep 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant