How can I run third-party scripts only when a visitor agrees?

Sometimes, to be compliant with privacy laws, you need to ask for consent before running a third-party script on your website. By third-party script, we mean a code, pixel, or tag that communicates and shares your visitor’s data with another service. In such cases, we recommend using Consent Manager, which allows you to display a consent pop-up and adding the appropriate types to tags, which will ensure that the tags only fire for visitors who agree.

In this article, we’ll explain how to set it up.

First, let’s look at an example of a consent form.

Consent form on a demo website from Piwik PRO

Here a visitor can decide for which purposes his data can be processed. The purposes correspond to the tag types that you run on your website.

Remarketing consent type in Piwik PRO

So when you have tags responsible for collecting analytics data, you set up the following tag type: Analytics. And when you have tags responsible for remarketing, you apply the following tag type: Remarketing. And so on. You can also create your own tag type or use a type: Does not require consent. In the latter case, the tag will be fired to all visitors, no matter if they agree or not.

Now coming back to running third-party scripts for visitors, here are the steps you should consider:

  1. Make a list of all third-party scripts that you use on your website. These may be scripts responsible for remarketing, customer contact or other advertising or supportive tools that you use.
  2. As a part of your audit, you can use our cookie scanner to see which cookies — first-party and third-party — you use on your website.
    Cookie scanner in Piwik PRO
  3. We recommend that you add all third-party scripts via Tag Manager because you’ll be able to use the mechanism that fires tags to visitors who agree to a particular script purpose.
  4. Assign appropriate types to tags that run third-party scripts.
    Remarketing tag type in Piwik PRO

    Tip: You can access this setting by going to Menu > Tag Manager > select a tag > Advanced tag settings.

  5. Adjust messages in the consent form in Consent Manager.
    Consent form in Piwik PRO

    Tip: You can access this setting by going to Menu > Consent Manager > Consent templatesConsent form.

  6. We also recommend that you create an internal process for adding all scripts, including third-party scripts, via Tag Manager. Each added script should have an appropriate tag type. This will help you keep all scripts organized and assigned to relevant consents.

Was this article helpful?

Technical support

If you still have any questions, visit our community.
There’s always someone happy to help!

Back to help center