Google Tag Manager

Setup

  1. First thing you should do is create an account/container for your site on Google Tag Manager.
  2. Now copy the Container ID to the appropriate setting on your site.

GA4

Setup the GA4 Tag

  1. Navigate to your container within Google Tag Manager.
  2. Click on "Tags" on the left, click "New".
  3. Under "Tag Configuration" select the "Google Analytics: GA4 Configuration" tag.
  4. Enter your GA4 Measurement ID.
  5. Under "Triggering" select the "All Pages" trigger.
  6. Save the tag.

Setup the GA4 Ecommerce Events Tag

  1. Navigate to your container within Google Tag Manager.
  2. Click on "Tags" on the left, click "New".
  3. Under "Tag Configuration" select the "Google Analytics: GA4 Event" tag.
  4. Change the "Configuration Tag" to your existing "Google Analytics GA4 Configuration" tag.
  5. Under "Event Name" select the "Event" variable.
  6. Click "More settings" and select "Send Ecommerce data".
  7. Under "Triggering" select the "Ecommerce Events" trigger if one exists, otherwise click the plus button in the top right corner to add a new trigger.
  8. Click to select a trigger type and select "Custom Event".
  9. Enter "view_item_list|view_item|select_item|add_to_cart|remove_from_cart|begin_checkout|add_shipping_info|add_payment_info|purchase" for the "Event Name" and check the "Use regex matching" checkbox.
  10. Now save the trigger as "Ecommerce Events".
  11. Finally save your tag.

Cookie Consent

Navigate to your container within Google Tag Manager and follow the instructions below:

Setup the Cookie Consent Tag

  1. Click on "Tags" on the left, click "New".
  2. Give it a name, e.g. "Consent Mode".
  3. Under "Tag Configuration" click "Discover more tag types in the Community Template Gallery" and search for "Consent Mode". Now select the "Consent Mode (Google tags)" template and click "Add to workspace".
  4. Configure the tag accordingly.
  5. Under "Triggering" select “Content Initialization - All Pages”.
  6. Finally save your tag.

Setup the Variables

  1. Click on "Variables" on the left, scroll down to "User-Defined Variables" and click "New".
  2. Give it a name, e.g. "Cookie Consent".
  3. Under "Variable Configuration" select "1st Party Cookie" and set the Cookie Name to "CookieConsent" and select “URI-decode cookie”
  4. Click "Save".

Follow the instructions below to setup additional variables to lookup the value of the variable above:

  1. Click "New" again to create another variable.
  2. Give it a name, e.g. "Lookup - Ad Storage". Alternatively you could setup a "Lookup - Analytics Storage" variable as an example.
  3. Under "Variable Configuration" select "Regex Tag", set the Input Variable to “{{ Cookie Consent }}” and Default Value to "denied".
  4. Click "Add Row", set the "Pattern" to "true" or "marketing:\true" (depending on the cookie value) and the "Output" to "granted".
  5. Under "Advanced Settings", disable "Full Matches Only" and disable "Enable Capture Groups and Replace Functionality".
  6. Click "Save".

Setup the Consent Mode - Update Tag

  1. Click on "Tags" on the left, click "New".
  2. Give it a name, e.g. "Consent Mode Update".
  3. Under "Tag Configuration" select "Consent Mode (Google tags)" under Custom (this is the same template as before but you no longer have to discover it).
  4. Change the Consent Command to "Update" and configure accordingly. For example, change "ad_storage" to the "{{ Lookup - Ad Storage }}" variable we created above. Similarly you could do the same for analytics etc.
  5. Under "Triggering" select “Content Initialization - All Pages”.
  6. Finally save your tag.

Testing

  1. Use the developer tools to delete the "CookieConsent" cookie.
  2. In Google Tag Manager, click "Preview".
  3. Click "Allow" in your cookie popup for your site and refresh the page.
  4. Now back in Google Tag Manager you should see how the second "Consent" message will update the consent state (click on the "Consent" tag to see).
  5. You should also test the scenario for when you click "Deny".

Finally you should apply the consent for your tags. Please go to https://youtu.be/yZjGzfWDc0Y?t=1195 for instructions on how to configure this.