> ## Knowledge Base Index
> Fetch the complete knowledge base index at: https://help.cookiewow.com/sitemap.xml
> Use this file to discover available pages before exploring further.
> Pure-Markdown content can be obtained by appending a '.md' suffix to the content URLs listed in the sitemap (without the trailing slash).

# How to Allow Google Analytics to Collect Anonymous Statistics Before User Consent (Google Tag Manager Setup)

**How to Allow Google Analytics to Collect Anonymous Statistics Before User Consent (Google Tag Manager Setup)**

If you're using Google Analytics via Google Tag Manager (GTM) and want to collect data anonymously before users give consent, here’s a step-by-step guide.  
> For websites using Google Analytics installed directly via HTML (not through GTM), refer to this guide: [Read setup instructions here](https://help.cookiewow.com/th/article/google-analytics-anonymous-ga-html-qvu3bf/)
---

### Note:
If your website collects personally identifiable information (PII) for analysis or marketing purposes, you must first obtain user consent according to PDPA laws.  
However, to ensure accurate visitor statistics — regardless of consent — you can **anonymize** data before consent is granted to reduce privacy risks.

### Principle:
Before consent is given, configure Google Analytics to:
* Not use cookies  
* Not collect granular identity details  
* Use **anonymized IP** by default ( [more info](https://support.google.com/analytics/answer/2763052?hl=en))  

Once consent is granted via the Cookie Wow banner, allow normal data collection with cookies.
---

## Step-by-Step Setup via Google Tag Manager

### ❶ Move the GTM & Analytics tags to the “Necessary” category:
* Place the following in the “Necessary” group, not “Analytics”:
* `https://www.googletagmanager.com/gtm.js?id=<GTM-KEY>`
* `https://www.google-analytics.com/analytics.js`
---

### ❷ Create a Variable to Check Consent Status

1. Open GTM, go to the **Variables** tab.
   ![](https://storage.crisp.chat/users/helpdesk/website/f1ac0320b192f000/screen-shot-2564-06-15-at-0850_1dl1mwj.png)

2. Create a new **Custom JavaScript Variable**.
   ![](https://storage.crisp.chat/users/helpdesk/website/f1ac0320b192f000/custom-javascript_wgixb6.gif)

3. Use this snippet (replace `'category-slug'` with the actual category slug you're using, usually 'Analytics'):

```javascript
function() {
  return window.cwcIsUserAccept('category-slug');
}
```

You can find the correct slug used in your Cookie Wow settings here: [How to find slugs](https://help.cookiewow.com/th/article/slug-199e1ow/)

4. Set "Convert null to false" and "Convert undefined to false"
5. Name it something like `cwcIsUserAcceptConsent`, then Save
   ![](https://storage.crisp.chat/users/helpdesk/website/f1ac0320b192f000/screen-shot-2564-06-14-at-1152_jga6if.png)
---

### ❸ Create Two Triggers (With/Without Consent)

#### A. Trigger for Users Who Have Not Given Consent

* Name: `Page View Trigger without User Consent`
* Type: Page View → **Some Page Views**
* Condition: `cwcIsUserAcceptConsent` equals `false`

![](https://storage.crisp.chat/users/helpdesk/website/f1ac0320b192f000/screen-shot-2564-06-14-at-1157_1wjwgnw.png)

#### B. Trigger for Users Who Have Given Consent

* Name: `Page View Trigger with User Consent`
* Type: Page View → **Some Page Views**
* Condition: `cwcIsUserAcceptConsent` equals `true`

![](https://storage.crisp.chat/users/helpdesk/website/f1ac0320b192f000/screen-shot-2564-06-14-at-1159_1cjz87s.png)
---

### ❹ Create Two GA Tags (One with, One without Consent)

#### A. Tag for Users Without Consent (Anonymous Tracking)

1. Name it: `Universal Analytics without User Consent`
2. Tag Type: Google Analytics: Universal Analytics
3. Track Type: Page View
4. Google Analytics Settings: Use your Tracking ID
5. Enable "Override settings in this tag"
6. Under More Settings, add these fields:

```plaintext
storage: none
storeGac: false
anonymizeIp: true
```

![](https://storage.crisp.chat/users/helpdesk/website/f1ac0320b192f000/screen-shot-2564-06-14-at-1206_azwoad.png)

7. Set Trigger to: `Page View Trigger without User Consent`
   ![](https://storage.crisp.chat/users/helpdesk/website/f1ac0320b192f000/screen-shot-2564-06-14-at-1208_1534rah.png)
---

#### B. Tag for Users With Consent (Normal Tracking)

1. Name it: `Universal Analytics with User Consent`
2. Tag Type: Google Analytics: Universal Analytics
3. Track Type: Page View
4. Use your GA Tracking ID
5. Set Trigger to: `Page View Trigger with User Consent`
   ![](https://storage.crisp.chat/users/helpdesk/website/f1ac0320b192f000/screen-shot-2564-06-14-at-1213_1wqln5i.png)
---
---