Manage Consent without Google Tag Manager
If a third-party script is installed directly in your site's HTML and cannot be moved into Google Tag Manager (GTM), you can add a consent requirement to the script with polaris.js.
Use this approach only for directly installed scripts. If your tags are managed by GTM, Shopify, or BigCommerce, use that integration instead.
GTM is the recommended option when it is available. GTM can check consent before it loads a tag. With the direct approach on this page, a script can still appear in the page or network activity before Polaris disables it, which can make verification less clear.
Before you begin
Confirm that:
polaris.jsis near the beginning of the<head>element and loads before the scripts you want to control.- The
polaris.jstag does not usedeferorasync. - You know which consent purpose each script requires.
See Getting Started if TrueVault is not yet installed on every page.
Supported consent purposes
Use one or more of these values in the data-polaris-consent attribute:
essentialmarketingpreferencesstatisticstv_not_opted_out
When you provide multiple comma-separated purposes, the script runs only when all of them are allowed.
Control an external script
Add data-polaris-consent to the script tag:
<script data-polaris-consent="statistics" src="stats-script.js"></script>
<script data-polaris-consent="marketing,preferences" src="ad-script.js"></script>
In this example, stats-script.js requires statistics consent. ad-script.js requires both marketing and preferences consent.
Control an inline script
Use the same attribute on an inline script:
<script type="text/javascript" data-polaris-consent="marketing">
console.log("I need marketing consent to run")
</script>
<script type="text/javascript" data-polaris-consent="statistics,marketing">
console.log("I need both statistics and marketing consent to run")
</script>
Verify the behavior
Test the page with each consent state your banner supports. Confirm that each controlled script runs only when all of its required purposes are allowed.
Note that a directly installed script's initial network request can be issued before Polaris disables the script, so automated consent scans may report it as not respecting consent. Use your browser's network inspector to verify that the script does not run or transmit data when its required purposes are declined.