> ## 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).

# การอัปเดตเป็น Google Consent V2

บทความนี้จะช่วยแนะนำวิธีการอัปเดตการตั้งค่า Google Consent ไปเป็นเวอร์ชัน 2 คุณสามารถดูข้อมูลอย่างเป็นทางการได้จาก [ที่นี่](https://developers.google.com/tag-platform/security/guides/consent?consentmode=advanced#set_up_consent_mode)
1. ตรวจสอบ **<script>** tag ในปัจจุบันของคุณที่ใช้งานร่วมกับ Google Tag หรือ Google Analyticsตัวอย่าง (ก่อนอัปเดต):
```
<script async src="<https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX>"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag() { dataLayer.push(arguments); }
  gtag('js', new Date());
  gtag('consent', 'default', {
    'ad_storage': 'denied',
    'analytics_storage': 'denied'
  });
  gtag('config', 'G-XXXXXXXXXX');
</script>
```
ส่วนที่สำคัญคือ:
```
gtag('consent', 'default', {
    'ad_storage': 'denied',
    'analytics_storage': 'denied'
  });
```
เพราะสำหรับ Google Consent V2 ต้องมีการเพิ่มค่าความยินยอมเพิ่มเติม
1. เพิ่มข้อมูลการขอความยินยอมเพิ่มเติมดังนี้ (โค้ดหลังอัปเดต):
```
gtag('consent', 'default', {
  'ad_storage': 'denied',
  'ad_user_data': 'denied',
  'ad_personalization': 'denied',
  'analytics_storage': 'denied'
});
```
บรรทัดนี้คือส่วนที่เพิ่มเข้ามา:

```
'ad_user_data': 'denied',
  'ad_personalization': 'denied'
คุณยังต้องเพิ่มสิ่งเหล่านี้ที่
<script>
  function consentGrantedAdStorage() {
    gtag('consent', 'update', {
      'ad_user_data': 'granted'
    });
    gtag('consent', 'update', {
      'ad_personalization': 'granted'
    });
  }
</script>
```
นี่คือเวอร์ชันสุดท้ายของสคริปต์ที่ใช้งานร่วมกับ Cookie Wow:

```
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag() {
    window.dataLayer.push(arguments);
  }

  // Initialize Google Analytics with default consent settings
  gtag('js', new Date());

  gtag('consent', 'default', {
    'ad_storage': 'denied',
    'analytics_storage': 'denied',
    'ad_user_data': 'denied',

 'ad_personalization': 'denied',
  });
```

  // Define wrapper to update consent if user accepts
 
```
 function cwcCookieWrapper() {
    if (window.cwcIsUserAccept && window.cwcIsUserAccept('analytics')) {
      gtag('consent', 'update', {
        'analytics_storage': 'granted'
      });
    }

    if (window.cwcIsUserAccept && window.cwcIsUserAccept('marketing')) {
      gtag('consent', 'update', {
        'ad_storage': 'granted',
        'ad_user_data': 'granted',
        'ad_personalization': 'granted'
      });
    }
  }
</script>
```

ตอนนี้คุณสามารถทดสอบการตั้งค่าได้เลย
