Hold back tracking and advertising code by default until visitors accept its category

Paste each tracking, advertising, or chat script into the Vendor Scripts tab of the Cookie Consent kit, and by default it waits for the visitor to accept its category. Vendor scripts belong to the Cookie Consent kit in TermsFeed AutoTerms, so a turned-off kit does not print any of them, with or without consent. Open TermsFeed > Compliance Kits, click the "Configure" button in the Cookie Consent box, and select the "Vendor Scripts" tab.

The 4 vendor script types and when each one runs

Each Type is a category of TermsFeed Free Cookie Consent 4.2.0. The columns assume the page_load_consent_levels list each Compliance preference sets: ["strictly-necessary"] under GDPR and all 4 categories under ePrivacy.

Type on the add form Category With the GDPR preference (express, default list) With the ePrivacy preference (implied, default list)
"Strictly Necessary (i.e. account login related cookies)" strictly-necessary Runs on every page load Runs on every page load
"Functionality (i.e. remembering user choices)" functionality Runs after the visitor accepts functionality Runs on every page load until the visitor turns it off
"Tracking and Performance (i.e. Google Analytics)" tracking Runs after the visitor accepts tracking Runs on every page load until the visitor turns it off
"Targeting and Advertising (i.e. Google AdSense, Google AdWords)" targeting Runs after the visitor accepts targeting Runs on every page load until the visitor turns it off

The visitor accepts the categories on the consent banner or in the Preferences Center. Put each tool in the category visitors expect with The 4 Cookie Categories in Free Cookie Consent.

How to add a vendor script

  1. Type a Name, such as "Google Analytics". The page source labels the script with it.
  2. Choose a Type from the 4 categories.
  3. Paste the complete vendor code into Script, <script> tags included.
  4. Click the "Add vendor script" button. The script appears as a row of the "Vendor Scripts" table.
  5. Click the "Save Changes" button. A row added without saving disappears when you leave the tab.
  6. Clear your page cache. Close every private window, open a new one, open Chrome DevTools, select the Network tab, type the vendor host in the filter box, and load your WordPress website. Under the GDPR preference, confirm that no request appears before you answer the consent banner, and that it appears after you accept the category.

The "Add vendor script" button refuses an incomplete entry with an alert that names the field to fix, such as "Please enter a Name for the vendor script.".

The Vendor Scripts tab with the add form filled in for Google Analytics, the Add vendor script button marked, and a Meta Pixel row

What the plugin keeps and drops from the vendor code you paste

The plugin prints every JavaScript <script> of the pasted code with its src, its attributes, and its code, and replaces its type so that it waits for its category. async, defer, data-* attributes, and a vendor id reach the page with their values.

  • A data block such as JSON-LD (application/ld+json) prints as it is, never runs, and needs no consent.
  • A <script type="module"> runs as a module once its category runs.
  • Code with no <script> tag becomes a single script, unless it starts with an HTML tag, which the "Add vendor script" button refuses.
  • Every other HTML element beside a <script>, such as <noscript>, <img>, and <iframe>, is dropped, because that markup loads without consent.
  • Scripts inside HTML comments never print.

Warnings in the "Vendor Scripts" list

A row shows a red warning when its code never reaches your WordPress website or never runs.

Warning in the row Fix
"No Type: this script never loads. Choose a Type, then click Save Changes." Pick a Type in the "- Select Type -" list of the row, then click the "Save Changes" button
"No <script> tag: this code is not added to your website. Delete it and add the <script> code of the vendor." Delete the row and add the <script> code of the vendor
"Incomplete <script> tag (e.g. no closing </script>): this code is not added to your website, or only in part. Delete it and add the complete code of the vendor." Delete the row and add the complete vendor code

A row without a warning runs once your Compliance preference or the visitor allows its category. Find every other reason a vendor script never runs in Vendor Script Never Runs in WordPress.

The id the plugin gives each vendor script

A vendor script without an id of its own gets termsfeed-autoterms-cookie-consent-vendor-script- followed by its Name in lower case, letters and digits only. The Name "Google Analytics" gives termsfeed-autoterms-cookie-consent-vendor-script-googleanalytics, and the n-th script of the same entry adds -n, such as -2. Use the id to find a vendor script in the Elements tab or to target it from a test.

How to reorder, delete, or change a vendor script

The plugin prints vendor scripts in the order of the list, so put a script above the scripts that depend on it. Use the "Move Up", "Move Down", and "Delete" buttons, then click the "Save Changes" button. The list has no edit button.

  1. Add the corrected code as a new vendor script.
  2. Delete the old row.
  3. Move the new row into place and click the "Save Changes" button.

Only a user with unfiltered_html saves vendor scripts. Fix a vendor script that did not save with Code or HTML Not Saving in WordPress.

Add Google Analytics 4 as a vendor script

Add the Google tag of Google Analytics 4 as a tracking vendor script, and under the default GDPR preference Google Analytics 4 sends nothing before the visitor accepts tracking. Copy the code from Admin > Data collection and modification > Data streams > Web > your web stream > View tag instructions > Install manually.

  1. Type the Name "Google Analytics" and choose "Tracking and Performance (i.e. Google Analytics)".
  2. Paste the code into the "Script" field and click the "Add vendor script" button.
  3. Click the "Save Changes" button.

The tag you copy looks like this, with your Measurement ID in place of G-XXXXXXXXXX.

<!-- Google tag (gtag.js) -->
<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('config', 'G-XXXXXXXXXX');
</script>

The plugin prints the 2 scripts in the footer of every page, tagged for the tracking category, without the leading <!-- Google tag (gtag.js) --> comment.

<!-- Cookie Consent by TermsFeed https://www.TermsFeed.com - GOOGLE ANALYTICS Vendor Script -->
<script type="text/plain" id="termsfeed-autoterms-cookie-consent-vendor-script-googleanalytics" data-cookie-consent="tracking" async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>
<script type="text/plain" id="termsfeed-autoterms-cookie-consent-vendor-script-googleanalytics-2" data-cookie-consent="tracking">
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'G-XXXXXXXXXX');
</script>
<!-- End of Cookie Consent by TermsFeed https://www.TermsFeed.com - GOOGLE ANALYTICS Vendor Script -->

Check the result in the page source and in the Network tab.

  1. Clear your page cache, open the page source of your WordPress website, and search for GOOGLE ANALYTICS Vendor Script to find the tagged scripts.
  2. Close every private window. Open a new one, open Chrome DevTools, select the Network tab, type googletagmanager.com in the filter box, and load any page. With the GDPR preference, no request appears before you answer, and gtag/js returns status 200 after a click on the "I agree" button.

Google Consent Mode v2 needs default signals in the <head> and updates from the Callbacks of the kit. Add both with Cookie Consent Callbacks in WordPress.