# Google Analytics and Onetrust cookie consent

**URL:** <https://community.hubspot.com/t/google-analytics-and-onetrust-cookie-consent/36577>\
**Category:** APIs & Integrations\
**Tags:** cms-content\
**Created:** [May 1, 2021, 12:20pm UTC](https://community.hubspot.com/t/google-analytics-and-onetrust-cookie-consent/36577 "2021-05-01T12:20:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![FSantgada](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/fsantgada/32/22074_2.png) [@FSantgada](https://community.hubspot.com/u/FSantgada)\
**Post date:** [May 1, 2021, 12:20pm UTC](https://community.hubspot.com/t/google-analytics-and-onetrust-cookie-consent/36577/1 "2021-05-01T12:20:37Z")

</div>

Hi All,

How can integrate Onetrust with Google analytics on my site?

I inserted on site Onetrust cookie banner and Google analytics.

If I visit the site Google analytics works independently if you accept cookies or not and send track event.

I would manage Google Analytics from Onetrust and send track of Google analytics only when user accept cookie.

Is it possible? How can I do?

How configure GA with hubspot and Onetrust (use is mandatory)?

An example or article is more appreciate.

Thanks

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [May 3, 2021, 9:00pm UTC](https://community.hubspot.com/t/google-analytics-and-onetrust-cookie-consent/36577/2 "2021-05-03T21:00:53Z")

</div>

[@Mike\_Eastwood](https://community.hubspot.com/t5/user/viewprofilepage/user-id/9259) , have you configured anything like this before?

---

<div class="post-metadata">

**Author:** ![FSantgada](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/fsantgada/32/22074_2.png) [@FSantgada](https://community.hubspot.com/u/FSantgada)\
**Post date:** [May 5, 2021, 8:26am UTC](https://community.hubspot.com/t/google-analytics-and-onetrust-cookie-consent/36577/3 "2021-05-05T08:26:37Z")

</div>

At the end I used a piece of code similar to this:

\<script\> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);}  
gtag(‘set’, ‘developer\_id.dNzMyY2’, true);  
gtag(‘consent’, ‘default’, {‘analytics\_storage’: ‘denied’}); gtag(‘consent’, ‘default’, {‘ads\_storage’: ‘denied’}); \</script\>

In your OneTrust CDN tag, make sure to implement the additional logic in the OptanonWrapper function.

\<script type=“text/javascript”\>  
function OptanonWrapper() {  
if (OnetrustActiveGroups.indexOf(‘C0002’) != -1)  
{ gtag(‘consent’, ‘update’, {‘analytics\_storage’: ‘granted’})};  
if (OnetrustActiveGroups.indexOf(‘C0004’) != -1)  
{ gtag(‘consent’, ‘update’, {‘ads\_storage’: ‘granted’})};  
}  
\</script\>
