# Hubspot consent banner and PiwikPro tracking

**URL:** <https://community.piwik.pro/t/hubspot-consent-banner-and-piwikpro-tracking/2137>\
**Category:** Data collection and tags\
**Created:** [May 5, 2023, 9:48am UTC](https://community.piwik.pro/t/hubspot-consent-banner-and-piwikpro-tracking/2137 "2023-05-05T09:48:27Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![seo](https://avatars.discourse-cdn.com/v4/letter/s/c5a1d2/32.png) [@seo](https://community.piwik.pro/u/seo)\
**Post date:** [May 5, 2023, 9:48am UTC](https://community.piwik.pro/t/hubspot-consent-banner-and-piwikpro-tracking/2137/1 "2023-05-05T09:48:27Z")

</div>

A client uses the Hubspot consent banner on their website. We have implemented the Piwik Pro script directly into the website code and disabled the Piwik consent manager.

How do I manage the Piwik Pro tracking trigger with the HubSpot consent manager?

I have added the triggers below:

- Page view with condition if cookie “\_\_hs\_initial\_opt\_in” = true (OK)
- OR History change (SPA) with condition if cookie “\_\_hs\_initial\_opt\_in” = true ( Not working)

Piwik Pro tracking only works when the page reloads.

Thanks

---

<div class="post-metadata">

**Author:** ![Jakub\_Fidala](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/jakub_fidala/32/1675_2.png) [@Jakub\_Fidala](https://community.piwik.pro/u/Jakub_Fidala)\
**Post date:** [May 5, 2023, 8:37pm UTC](https://community.piwik.pro/t/hubspot-consent-banner-and-piwikpro-tracking/2137/2 "2023-05-05T20:37:56Z")

</div>

Is there dataLayer event sent with accepting cookies consent? Maybe add this one as well + cookie=true. Right now you are sending first entry page view with cookie=true (which is false), and then sending first page view on history change.

Maybe this workaround would help you.

---

<div class="post-metadata">

**Author:** ![Oliwer\_Kaczmarek](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/oliwer_kaczmarek/32/3888_2.png) [@Oliwer\_Kaczmarek](https://community.piwik.pro/u/Oliwer_Kaczmarek)\
**Post date:** [May 5, 2023, 9:00pm UTC](https://community.piwik.pro/t/hubspot-consent-banner-and-piwikpro-tracking/2137/3 "2023-05-05T21:00:30Z")

</div>

Hi @seo,

To have annonymous tracking as well I would recommend this set-up:

In administration \> [site or app] \> privacy:

- _ask visitor for consent_ - turned ON
- _Use a custom consent form_ - turned ON

Those settings will allow you to use consent manager methods without having our consent form shown to visitors.

Once you’ve done this part, now you should go to tag manager and create couple things:

1. Custom JS Tag with this script in:

```auto
<script>
    window._paq = window._paq || [];
    ppms.cm.api('getComplianceSettings', (e)=>{
        if(e.consents.analytics.status !== 1) {
            ppms.cm.api('setComplianceSettings', {consents: {analytics: {status: 1}}}, ()=>{}, ()=>{});
            _paq.push(["deanonymizeUser"]);
        }
    }, ()=>{});
</script>

```

1. A trigger for the tag above that will fire on each page view where the cookie you’ve mentioned had value true.

Each new visitor is seen as anonymous by default so only after triggering this tag they will be seen as not anonymous.

With this kind of set-up you don’t have to worry about the additional condition for cookie value in each trigger you use, you simply set tags that you don’t want to fire for anonymous users as “consent type: analytics” and tags for every visitor “consent type: No consent is required”

In case you don’t want to track anything from anonymous users, than in _administration \> [site or app] \> privacy_ you also change this:

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/piwikpro/original/2X/5/5248069967cd3bb1bc0ac2dbf591e36c9c165c9d.png)

This solution might take some time to set-up correctly and debug to make sure everything works as expected, so you might consider workaround of @Jakub_Fidala.

---

<div class="post-metadata">

**Author:** ![seo](https://avatars.discourse-cdn.com/v4/letter/s/c5a1d2/32.png) [@seo](https://community.piwik.pro/u/seo)\
**Post date:** [May 8, 2023, 8:21am UTC](https://community.piwik.pro/t/hubspot-consent-banner-and-piwikpro-tracking/2137/4 "2023-05-08T08:21:00Z")

</div>

Unfortunately there is no dataLayer event with accepting cookies consent.

---

<div class="post-metadata">

**Author:** ![seo](https://avatars.discourse-cdn.com/v4/letter/s/c5a1d2/32.png) [@seo](https://community.piwik.pro/u/seo)\
**Post date:** [May 8, 2023, 8:50am UTC](https://community.piwik.pro/t/hubspot-consent-banner-and-piwikpro-tracking/2137/5 "2023-05-08T08:50:33Z")

</div>

I added this tag and changed the setting as indicated but I think I missed something as the cookie seems to be there before the user choice.

Before accepting the cookies I see this in debug mode:  
 ![image](https://europe1.discourse-cdn.com/flex005/uploads/piwikpro/original/2X/6/69d268ddc596c09d9a7a6b7de8846cf1f2a936c3.png)

**basic tracking code**

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/piwikpro/original/2X/4/4050ea8dd8688cdbdfc817b894b8c766d27473a0.png)

**Custom JS Tag**

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/piwikpro/original/2X/4/4e02fcc400e811bd26f0f6963d217fb18535ea28.png)

**Trigger for Custom JS Tag**

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/piwikpro/original/2X/5/5e9481514ed9aa2e3ec27be49d0ca2af6792b4be.png)

**Administration \> site \> privacy**

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/piwikpro/original/2X/0/0ecae1a65a646e9015a2700c1041c09c39abded8.png)

---

<div class="post-metadata">

**Author:** ![Oliwer\_Kaczmarek](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/oliwer_kaczmarek/32/3888_2.png) [@Oliwer\_Kaczmarek](https://community.piwik.pro/u/Oliwer_Kaczmarek)\
**Post date:** [May 8, 2023, 10:33am UTC](https://community.piwik.pro/t/hubspot-consent-banner-and-piwikpro-tracking/2137/6 "2023-05-08T10:33:22Z")

</div>

This tag should fire only when visitor give a consent. By the description of the situation, it sounds to me like the trigger is fired immidietly on the page, which by the look of the trigger (page load), I think is true. You have to use a cookie value that is only true once consent is given (or a cookie that is created only when consent is given).

---

<div class="post-metadata">

**Author:** ![seo](https://avatars.discourse-cdn.com/v4/letter/s/c5a1d2/32.png) [@seo](https://community.piwik.pro/u/seo)\
**Post date:** [May 10, 2023, 10:08am UTC](https://community.piwik.pro/t/hubspot-consent-banner-and-piwikpro-tracking/2137/7 "2023-05-10T10:08:11Z")

</div>

The cookie (“\_\_hs\_initial\_opt\_in”) I’m relying on for the trigger is only true when the user consent.  
I have sent you the site as a message. Can you please check it?  
Thanks

---

<div class="post-metadata">

**Author:** ![Oliwer\_Kaczmarek](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/oliwer_kaczmarek/32/3888_2.png) [@Oliwer\_Kaczmarek](https://community.piwik.pro/u/Oliwer_Kaczmarek)\
**Post date:** [May 10, 2023, 1:12pm UTC](https://community.piwik.pro/t/hubspot-consent-banner-and-piwikpro-tracking/2137/8 "2023-05-10T13:12:21Z")

</div>

From what I see there is no `ppms_privacy_<appID>` cookie on the website, is it blocked by your consent manager? Consent manager requires this cookie to be present on site all the time to work properly. Here is more information about our cookies [Cookies created for visitors by Piwik PRO | Data and cookies | Piwik PRO help center](https://help.piwik.pro/support/privacy/cookies-created-for-visitors-by-piwik-pro/)

---

<div class="post-metadata">

**Author:** ![seo](https://avatars.discourse-cdn.com/v4/letter/s/c5a1d2/32.png) [@seo](https://community.piwik.pro/u/seo)\
**Post date:** [May 10, 2023, 2:10pm UTC](https://community.piwik.pro/t/hubspot-consent-banner-and-piwikpro-tracking/2137/9 "2023-05-10T14:10:21Z")

</div>

Could Hubspot block this cookie? 😑  
I’m going to ask the client for more information.  
Thanks!

---

<div class="post-metadata">

**Author:** ![seo](https://avatars.discourse-cdn.com/v4/letter/s/c5a1d2/32.png) [@seo](https://community.piwik.pro/u/seo)\
**Post date:** [May 11, 2023, 2:22pm UTC](https://community.piwik.pro/t/hubspot-consent-banner-and-piwikpro-tracking/2137/10 "2023-05-11T14:22:56Z")

</div>

I found Hubspot’s documentation for getting the consent status :

> **[Cookie banner](https://developers.hubspot.com/docs/api/events/cookie-banner#:~:text=Get%20privacy%20consent%20status)**
>
> The cookie consent banner enables you to enable/disable different analytics scripts based on user preferences.

So I tried this (I am not web developer):

```auto
<script>
window._paq = window._paq || [];
var _hsp = window._hsp = window._hsp || [];

_hsp.push(['addPrivacyConsentListener', function(consent) {
    console.log(consent);
    var analyticsConsent = consent.categories.analytics;
  
    if (analyticsConsent !== true) {
        ppms.cm.api('setComplianceSettings', { consents: { analytics: { status: -1 } } });
        _paq.push(["setUserIsAnonymous", true]);
    } else {
        ppms.cm.api('setComplianceSettings', { consents: { analytics: { status: 1 } } });
        _paq.push(["deanonymizeUser"]);
    }
}]);
</script>

```

but I still see this in debug mode (without clicking on the consent banner)… :  
 ![image](https://europe1.discourse-cdn.com/flex005/uploads/piwikpro/original/2X/e/eecfaad5c224075cba8ea4f93d49601d99d4e37c.png)

---

<div class="post-metadata">

**Author:** ![Oliwer\_Kaczmarek](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/oliwer_kaczmarek/32/3888_2.png) [@Oliwer\_Kaczmarek](https://community.piwik.pro/u/Oliwer_Kaczmarek)\
**Post date:** [May 12, 2023, 11:17am UTC](https://community.piwik.pro/t/hubspot-consent-banner-and-piwikpro-tracking/2137/11 "2023-05-12T11:17:54Z")

</div>

That’s correct, you should see it, as the current script you have should fire before consent is given. Because you are using a listener that waits for a decision. So the consent itself is not changed until listener sees the hubspot event.

What I’ve noticed is missing part of the script.  
you need to have two functions at the end of set compliance settings. They are there for debugging purpose so I leave those empty but they are still required.  
So instead of this:

```auto
ppms.cm.api('setComplianceSettings', { consents: { analytics: { status: 1 } } });

```

You should have this:

```auto
ppms.cm.api('setComplianceSettings', { consents: { analytics: { status: 1 } } }, ()=>{}, ()=>{});

```

Other thing is you are changing status for -1 for not consenting visitors. You should use 0, as -1 is interpreted as visitors who didn’t made decision yet. From the data gathering point there is no difference as Piwik PRO considers not consenting and those who didn’t made a decision yet as the same. But the proper way is to have 0 once someone doesn’t consent.

And last thing, when opening site as a new visit, I still don’t see our consent cookie, so please take a look at this issue.
