# Disable any tracking after changing to NOT consent with custom consent form

**URL:** <https://community.piwik.pro/t/disable-any-tracking-after-changing-to-not-consent-with-custom-consent-form/1696>\
**Category:** Privacy\
**Created:** [February 28, 2023, 4:35pm UTC](https://community.piwik.pro/t/disable-any-tracking-after-changing-to-not-consent-with-custom-consent-form/1696 "2023-02-28T16:35:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arturr](https://avatars.discourse-cdn.com/v4/letter/a/919ad9/32.png) [@Arturr](https://community.piwik.pro/u/Arturr)\
**Post date:** [February 28, 2023, 4:35pm UTC](https://community.piwik.pro/t/disable-any-tracking-after-changing-to-not-consent-with-custom-consent-form/1696/1 "2023-02-28T16:35:06Z")

</div>

Im trying to disable any tracking whatsoever when user do NOT consent while having custom consent system. I need to have full control of tracking, full - meaning no tracking at all even anonymous data, pings etc. when user did NOT consent. **I also want to have option to change decision any time!**

Im having SPA application.  
Sending events manualy (want to have full control).

My configuration:

 ![piwik_admin_sitesapps_datacollection](https://europe1.discourse-cdn.com/flex005/uploads/piwikpro/original/2X/7/7bad6e4b6929327d4393a38b560e6efee54ac232.png)  
 ![piwik_admin_sitesapps_privacy1](https://europe1.discourse-cdn.com/flex005/uploads/piwikpro/original/2X/3/392ec2d5dfb28b2f7e1711c632887e15f3299824.png)  
 ![piwik_admin_sitesapps_privacy2](https://europe1.discourse-cdn.com/flex005/uploads/piwikpro/original/2X/2/247a84a99e2d6abc362f24e782596127811144c9.png)  
 ![piwik_tagmanager_piwik](https://europe1.discourse-cdn.com/flex005/uploads/piwikpro/original/2X/b/b8dfcf8bec0f6ae3674ae651e5041edfe73795e6.png)

In general GoogleAnalytics or Matomo have this easy to control simple flag which you set and all tracking is disabled. Im looking for something like that with no success.  
**Matomo way:** `_paq.push(['rememberConsentGiven', ...]);` / `_paq.push(['forgetConsentGiven', ...]);`  
**GoogleAnalytics way:** `window[`ga-disable-${trackingId}`] = false;`

So I followed some custom consent form guidelines and read dev documentation.

> **[Turn on or off the consent form on your site | Piwik PRO help center](https://help.piwik.pro/support/privacy/setting-consent-manager/)**
>
> When you use Consent Manager, the consent form automatically appears on your site with its default setup. In this article, we’ll show you where to change its settings and how to turn them off if you ever need to. To turn on or off the consent form on...

> **[How can I integrate a third-party cookie consent tool with Piwik PRO? | Piwik...](https://help.piwik.pro/support/privacy/how-can-i-integrate-a-third-party-cookie-consent-tool-with-piwik-pro/?pk_vid=1677258601cf9a92)**
>
> If you want to keep using your cookie consent tool and don’t want to switch to our Consent Manager, you can integrate it with Piwik PRO. This way, you’ll be able to collect full data from visitors who gave their consent and anonymous data from the...

Implemented how it should be according to docs as I understood it.  
Setting at start: `ppms.cm.api('setInitialComplianceSettings', { consents: ['analytics']});`  
Then when user makes action to accept / decline consents OR user already did it before (flag from BE response): `ppms.cm.api('setComplianceSettings', { consents: { analytics: { status: consentValue ? 1 : 0 } } });`  
I even check if its set in cookies / storage and calling ‘ **getComplianceSettings** ’ command, every source shows its changed properly.

Everything is working properly at start.  
**Case accepted:** ppms.js script is downloaded and some events are send in network and are visible on Tracker debugger.  
**Case declined:** ppms.js script is NOT downloaded and no events are send in any way.

But when user changes mind and goes to change what was chosen before, then it seems like its not working as it should.  
**Case accepted → declined:** pings are sent anyway unless you change “Count session time precisly” (would be nice to have those pings when accepted but not when declined), all manually triggered commands like trackPageView still sending events to Piwik system (can see them on Tracker debugger and browser’s network), I could make manual condition to not send any events if internal consent flag is false, but how can I be sure if something else would be send automatically which I didnt configured or there are some bugs or other unpredictable things (risk of breaking laws)  
**Case declined → accepted:** ppms.js script is downloaded, and seems like everything works as it should  
**Case accepted → declined → accepted:** same as above but getting error

```auto
ppms.js conflict
ppms.js:12 Matomo javascript tracker or Piwik PRO javascript tracker was already initiated on this page. Please check the tracker setup. Matomo conflict can be resolved using these instructions: https://help.piwik.pro/support/questions/can-i-use-piwik-pro-and-matomo-at-the-same-time/.

```

**I do not use Matomo** , its happening everytime I use command “ **setComplianceSettings** ”, with “ **accepted** ” payload (ppms.js script is downloaded again).

Seems like “ **setComplianceSettings** ” might be one use command (you only set it once and should not do it twice). So how can I change consent to _false_ anytime with custom consent form? I saw opt-out form, but **not custom** one, so I assumed my custom form is enough, and I just have to use “ **setComplianceSettings** ” again (did not see any info about this command to be invoked only once per application life).

**To summarize:**

1. How to properly change consent if its been already set before with CUSTOM consent form ( **both ways** )?
2. If using “ **setComplianceSettings** ” command multiple times with different payload is proper way, then what about this conflict ppms.js error?
3. How to have “ **Count session time precisly** ” turned on when user consent but not having pings when user did not consent? manual heartbeat? (unless Im doing it wrong and it should be blocked when consent is declined after agreeing to it)
4. Is there disable flag like GA or Matomo has?

---

<div class="post-metadata">

**Author:** ![Admin](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@Admin](https://community.piwik.pro/u/Admin)\
**Post date:** [March 1, 2023, 5:58pm UTC](https://community.piwik.pro/t/disable-any-tracking-after-changing-to-not-consent-with-custom-consent-form/1696/2 "2023-03-01T17:58:28Z")

</div>

Hi.

> all manually triggered commands like trackPageView still sending events to Piwik system (can see them on Tracker debugger and browser’s network), I could make manual condition to not send any events if internal consent flag is false, but how can I be sure if something else would be send automatically which I didnt configured or there are some bugs or other unpredictable things (risk of breaking laws)

If you want to set up virtual page views manually, I’d suggest doing it via our Tag Manager. In general, we rely heavily on the Tag Manager when it comes to firing tags and taking into account consent choices. If you need full control, I suggest firing the page views (and other important events) via dataLayer pushes. Those pushes can be then intercepted via Tag Manager tag with proper consent type set.

As for other described issues - does full page refresh fix mentioned problems?

---

<div class="post-metadata">

**Author:** ![Arturr](https://avatars.discourse-cdn.com/v4/letter/a/919ad9/32.png) [@Arturr](https://community.piwik.pro/u/Arturr)\
**Post date:** [March 2, 2023, 4:17pm UTC](https://community.piwik.pro/t/disable-any-tracking-after-changing-to-not-consent-with-custom-consent-form/1696/3 "2023-03-02T16:17:24Z")

</div>

Hello.  
I have played with PiwikPro more, and it seems like consents are working for **tags**.

(1) It seems like `_paq.push` commands are avoiding consent logic (consent dont have any effect on direct `_paq` commands), is it true and intended?

(2) Is there some kind of flag or command that entirely turns off PiwikPro scripts?

> As for other described issues - does full page refresh fix mentioned problems?

Refreshing page (F5) just initialize everything again so basically a restart.  
Everytime I send `setComplianceSettings` with **true** and compliance settings were in state **non-true** - **ppms.js** script is downloaded, so if I send `setComplianceSettings` more than once from **non-true** state to **true** , this error occurs ( **ppms.js** script “JavaScript tracking client” is downloaded again - looks like something that should not happen, this script is trying to init trackers again, dont know yet why its downloaded again). From **true** state to **true** state there is no error.  
By **true** and **non-true** , I mean: true = 1, non-true=-1 or 0. Btw. I did not see any problems when this error occurs, but its concerning and better to not have it (might not see everything that should or should not happen).

![piwik_ppms_x2](https://europe1.discourse-cdn.com/flex005/uploads/piwikpro/original/2X/b/b929a084574f6823000cb7f4084d491a4adde713.png)

(3) Can you confirm, that using `setComplianceSettings` multiple times on SPA and CUSTOM consent forms is the proper way to switch between consenting and not consenting?

---

<div class="post-metadata">

**Author:** ![Admin](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@Admin](https://community.piwik.pro/u/Admin)\
**Post date:** [March 3, 2023, 9:12am UTC](https://community.piwik.pro/t/disable-any-tracking-after-changing-to-not-consent-with-custom-consent-form/1696/4 "2023-03-03T09:12:22Z")

</div>

Let me first answer your questions from the previous message.

> 1. How to properly change consent if its been already set before with CUSTOM consent form ( **both ways** )?

The way you’re doing it is fine.

> 1. If using “ **setComplianceSettings** ” command multiple times with different payload is proper way, then what about this conflict ppms.js error?

It happens because changing consent type from rejected to accepted always fires all tag manager tags with given consent type assigned. This is a rather rare case and mentioned error doesn’t break the product. It simply clutters the console. We could think about a better message here or changing the error into warning.

> 1. How to have “ **Count session time precisly** ” turned on when user consent but not having pings when user did not consent? manual heartbeat? (unless Im doing it wrong and it should be blocked when consent is declined after agreeing to it)

Calling `_paq.push(["disableHeartBeatTimer"]);` should do the trick. I just tested it and for some reason it doesn’t work. I’ll let the product team check what’s wrong.

> 1. Is there disable flag like GA or Matomo has?

No, since all consent-related logic is handled by the tag manager.
