Linux 软件免费装
Banner图

Opt-Out for Google Analytics (DSGVO / GDPR)

开发者 schweizersolutions
更新时间 2026年10月30日 17:34
捐献地址: 去捐款
PHP版本: 7.4 及以上
WordPress版本: 7.1
版权: GPLv2 or later
版权网址: 版权信息

标签

google analytics gdpr dsgvo opt-out ga4

下载

1.8 1.5 2.2 2.6 1.0 1.4 1.6 2.1 2.7 2.7.1 1.1 1.3 1.7 1.9 2.0 2.3 2.4 1.2 2.5

详情介绍:

The General Data Protection Regulation (GDPR, German: DSGVO) requires that website visitors can object to the collection of their data by Google Analytics. Until now, this was only possible with a browser add-on or with complicated JavaScript code on your own website. With this plugin, it is child's play, and visitors can also undo their objection at any time. And the plugin makes sure that it stays that way: it checks regularly whether the opt-out still works on your website, and notifies you by email, in Slack, Microsoft Teams or Discord, or in your uptime monitoring, if something is wrong. Features Opt-out for your visitors Block, page builders and shortcode Status check and monitoring Settings and developers Regular check whether the opt-out still works Have you ever edited your privacy policy page and accidentally deleted the opt-out shortcode? Or removed your Google Analytics plugin, reinstalled it later and forgot to set up the tracking code again? Or does an optimization plugin delay the opt-out script, so it runs too late? To keep you on the safe side, the plugin checks the settings and the website regularly. If something is no longer correct, an error message appears in the WordPress admin and in the Site Health, and you receive an email. You can choose how often the check runs: daily, weekly or monthly. With "Check now" in the dashboard widget or on the settings page, it runs at any time. The following is checked: For agencies and multisite networks Built-in compatibility with the following plugins You do not need any of these plugins! The plugin also works with other plugins, or if you have added the Google Analytics code yourself. With the built-in compatibility, the current GA4 measurement ID is read automatically and kept up to date, so you never have to correct it manually. Privacy policy that is AUTOMATICALLY kept up to date Keeping track of all changes in data protection law is not easy, especially alongside your core business. That's why we offer a privacy policy generator together with our partner eRecht24. You create your privacy policy ONCE, and it is automatically kept up to date in WordPress. No more filling out forms and copying and pasting privacy statements: it is completely automated. More information: https://schweizer.solutions/erecht24 Do you like our plugin? A positive review motivates us a lot to keep working on our free plugins. Coded with love by Schweizer Solutions GmbH This plugin is not made or supported by Google. Google Analytics is a trademark of Google LLC.

安装:

Installation in WordPress
  1. In the admin, go to Plugins > Add New Plugin.
  2. Search for Opt-Out for Google Analytics.
  3. Click "Install Now".
  4. Activate the plugin.
Manual installation
  1. Download the ZIP file and unpack it.
  2. Upload the folder opt-out-for-google-analytics to the /wp-content/plugins/ directory of your WordPress installation.
  3. Activate the plugin.
Configuration
  1. In the admin, go to Settings > GA Opt-Out.
  2. Switch on "Enable Opt-Out function", if it is not enabled yet.
  3. Select the source of the GA4 measurement ID, or enter it manually.
  4. Select your privacy policy page, so the status check can monitor it.
  5. Save the changes.
  6. Add the link to your privacy policy: with the shortcode [ga_optout], the block, the Elementor widget or the Divi module "Opt-Out for Google Analytics". Done!
  7. Optional: in "Status check", set up the email addresses, a webhook (e.g. Slack or Microsoft Teams) or the status URL for your uptime monitoring.
All instructions can also be found in the help of the settings page ("Help" at the top right). Note on the GA4 measurement ID If you added the Google Analytics tracking code yourself, e.g. in your theme, enter the measurement ID in the input field. If you use one of the compatible Google Analytics plugins, you can select it as the source. The plugin then reads the current measurement ID automatically, and you do not need to enter it.

屏幕截图:

  • Shortcode inserted in the classic editor
  • Opt-out link with popup on the website
  • Example of a status email
  • Block in the block editor, with individual link and popup texts
  • Dashboard widget with the status check, also of the website
  • Multisite: status of all sites in the network admin, with filter, search and sorting, the check can be started for one or all sites
  • Multisite: settings of the network, with the status URL and the webhook for all sites, the template site, the transfer of the settings and the access of the site admins

升级注意事项:

2.7 Big update: the status check also checks your website, notifications by webhook (Slack, Teams, Discord), REST API for uptime monitoring, Google Consent Mode, multisite center, WP-CLI and a new settings page. Requires WordPress 6.3 and PHP 7.4. 2.5 Universal Analytics (UA-) codes are no longer supported. If you still use a UA code, switch to your Google Analytics 4 measurement ID (G-XXXXXXXXXX). Otherwise, the opt-out link will not be displayed.

常见问题:

Why should I use this plugin?

The General Data Protection Regulation (GDPR, German: DSGVO) requires that website visitors can object to the collection of their data by Google Analytics. Until now, this was only possible with a browser add-on or with complicated JavaScript code on your own website. With this plugin, it is very easy, and visitors can also undo their objection.

Is it the same opt-out code as the one from e-recht24.de?

Yes, because both follow Google's specifications for Google Analytics 4. More information: https://developers.google.com/tag-platform/security/guides/privacy#turn-off-analytics

I added the Google Analytics tracking code myself, in my theme or with another plugin. Can I still use this plugin?

Yes. The plugin also works if the tracking code was added to the theme manually or with another plugin.

Do I need to update my privacy policy? Can it be updated AUTOMATICALLY?

Yes, we recommend offering the opt-out for Google Analytics in your privacy policy. Keeping track of all changes in data protection law is not easy, especially alongside your core business. That's why we offer a privacy policy generator together with our partner eRecht24. You create your privacy policy ONCE, and it is automatically kept up to date in WordPress. No more filling out forms and copying and pasting privacy statements: it is completely automated. More information: https://schweizer.solutions/erecht24

How long does the opt-out remain valid?

When a visitor clicks the opt-out link, a cookie is set. This cookie tells the website not to track this visitor. The cookie is only valid in the browser in which the visitor clicked the opt-out link. In a different browser, the visitor has to click the link again. If the visitor clears their browser data (cookies, history, etc.), the cookie is deleted as well, and they have to click the opt-out link again.

How do I deactivate the plugin?

To turn off the opt-out function, go to Settings > GA Opt-Out and switch off "Enable Opt-Out function". To deactivate the whole plugin, go to Plugins > Installed Plugins and click "Deactivate" below "Opt-Out for Google Analytics". After deactivating the plugin, you can remove it completely by clicking "Delete".

Where can I use the shortcode?

You can use the shortcode [ga_optout] in posts, pages and widgets (text widget). In the block editor, you can also use the block "Opt-Out for Google Analytics", and in Elementor and Divi the widget or module with the same name.

Can I use different link and popup texts on one page?

Yes. In the Gutenberg block, the Elementor widget and the Divi module, you can enter individual link and popup texts in the settings. If you use the shortcode, add the texts as attributes: [ga_optout link_deactivate="Disallow tracking" link_activate="Allow tracking" popup_deactivate="Tracking is disabled." popup_activate="Tracking is enabled."] If a text is empty, the text from the plugin settings is used. With popup_type="notice" the popup text is shown below the link instead of a browser popup (popup_type="alert"), with force_reload="yes" or force_reload="no" the page is reloaded after the click or not. Without these attributes, the settings of the plugin are used. In the block, the Elementor widget and the Divi module, these options are in the settings too.

Can developers customize the plugin?

Yes. The plugin provides the following actions and filters: `// Before the shortcode is rendered add_action( 'gaoo_before_shortcode', 'my_before_shortcode', 10, 2); function my_before_shortcode( $tracking_code, $current_status ) { // $tracking_code - The measurement ID in use: "G-XXXXXXXXXX" // $current_status - The current status of the visitor: activate or deactivate } // After the shortcode is rendered add_action( 'gaoo_after_shortcode', 'my_after_shortcode', 10, 2); function my_after_shortcode( $tracking_code, $current_status ) { // $tracking_code - The measurement ID in use: "G-XXXXXXXXXX" // $current_status - The current status of the visitor: activate or deactivate } // Before the JavaScript code that disables GA is output add_action( 'gaoo_before_head_script', 'my_before_script', 10, 1); function my_before_script( $tracking_code ) { // $tracking_code - The measurement ID in use: "G-XXXXXXXXXX" } // After the JavaScript code that disables GA is output add_action( 'gaoo_after_head_script', 'my_after_script', 10, 1); function my_after_script( $tracking_code ) { // $tracking_code - The measurement ID in use: "G-XXXXXXXXXX" } // The GA4 measurement ID in use add_filter( 'gaoo_get_ua_code', 'my_ga_tracking_code', 10, 2 ); function my_ga_tracking_code( $tracking_code, $ga_plugin ) { // $tracking_code - The measurement ID in use: "G-XXXXXXXXXX" // $ga_plugin - The selected source of the measurement ID } // Whether the page should be reloaded after the click add_filter( 'gaoo_force_reload', 'my_force_reload', 10, 1); function my_force_reload( $force ) { // $force - "true" = reload the page; "false" = do not reload } // The texts from the settings (also: gaoo_link_activate_text, gaoo_popup_deactivate_text, gaoo_popup_activate_text) add_filter( 'gaoo_link_deactivate_text', 'my_link_text', 10, 1 ); function my_link_text( $text ) { // $text - The text from the settings return $text; } // The individual texts of a shortcode, block, Elementor widget or Divi module add_filter( 'gaoo_shortcode_atts', 'my_shortcode_atts', 10, 1 ); function my_shortcode_atts( $atts ) { // $atts - Array with the keys link_deactivate, link_activate, popup_deactivate, popup_activate, popup_type (alert, notice) and force_reload (yes, no). An empty value uses the settings. return $atts; } // The HTML code of the link, e.g. to add a wrapper. The class "gaoo-link" must be kept. add_filter( 'gaoo_shortcode_html', 'my_shortcode_html', 10, 4 ); function my_shortcode_html( $html, $tracking_code, $current_status, $atts ) { return ' ' . $html . ''; } // The status check: the page for the check of the website (default: home page) add_filter( 'gaoo_frontend_check_url', 'my_frontend_check_url', 10, 1 ); function my_frontend_check_url( $url ) { return home_url( '/privacy-policy/' ); } // The status check: whether the link was found on the privacy policy page, e.g. for page builders which store the content in their own format add_filter( 'gaoo_shortcode_found', 'my_shortcode_found', 10, 3 ); function my_shortcode_found( $found, $page_id, $page ) { // $found - true if the plugin found the link return $found || false !== strpos( (string) get_post_meta( $page_id, 'my_builder_content', true ), '[ga_optout' ); } // The status check: add own checks. They are shown in the dashboard widget, on the settings page and in the status email. add_filter( 'gaoo_status_checks', 'my_status_checks', 10, 2 ); function my_status_checks( $checks, $settings ) { $checks[] = array( 'id' => 'cookie_banner', // Optional: unique ID of the check, e.g. for the REST API. The last check with the same ID wins. 'label' => 'Cookie banner is active', // Text of the check 'checked' => is_plugin_active( 'my-cookie-banner/my-cookie-banner.php' ), // true = passed, false = failed, null = unknown 'url' => admin_url( 'plugins.php' ), // Optional: page to fix the check ); return $checks; } // After every status check (automatic or "Check now"), e.g. to send the result to another service add_action( 'gaoo_status_check_done', 'my_status_check_done', 10, 2 ); function my_status_check_done( $checks, $failed ) { // $checks - List of the checks with the keys "label" and "checked" // $failed - true if at least one check failed } // Data of the webhook, sent as JSON (format: json, slack, teams or discord) add_filter( 'gaoo_webhook_payload', 'my_webhook_payload', 10, 4 ); function my_webhook_payload( $payload, $format, $checks, $network ) { // $network - true for the webhook of the network (multisite) return $payload; } // Number of sites per page in the overview of the network (default: 50) add_filter( 'gaoo_network_per_page', function () { return 100; } ); // The status email, which is only sent if a check failed (also: gaoo_status_mail_subject, gaoo_status_mail_body) add_filter( 'gaoo_status_mail_recipients', 'my_status_mail_recipients', 10, 2 ); function my_status_mail_recipients( $recipients, $checks ) { // $recipients - Array of email addresses. An empty array sends no email. $recipients[] = 'monitoring@example.org'; return $recipients; } `

My theme does not render shortcodes. How can I add the link with PHP?

Some custom themes do not render shortcodes, so the link is not displayed. In this case, add the following code to your theme at the desired position: echo do_shortcode('[ga_optout]');

The status check reports a problem, although I have already fixed it!

If you changed a setting, e.g. in a compatible Google Analytics plugin, the change is only detected during the next automatic check (daily, weekly or monthly, depending on your settings). You can run the check right away: click "Check now" in the dashboard widget or on the settings page Settings > GA Opt-Out. The next automatic check is then moved by the interval.

How can I react to the clicks, e.g. with another plugin?

The plugin fires the JavaScript event gaoptout on the window object. If the visitor clicks the link to opt out, event.detail is true. If the visitor opts in again, it is false. Example: window.addEventListener('gaoptout', function (e) { console.log(e.detail); }); With jQuery, the value is available in e.originalEvent.detail.

How do I change the appearance of the link?

You can change the appearance of the link with custom CSS in the plugin settings. The following CSS classes are available: The link itself: .gaoo-link { ... } The ID #gaoo-link still works for compatibility, but please use the CSS class. The ID is not unique if the link is used several times on one page. The link if the visitor has opted out of tracking: .gaoo-link-activate { ... } The link if the visitor has NOT opted out of tracking: .gaoo-link-deactivate { ... } The notice below the link, if the popup text is not shown as a browser popup: .gaoo-notice { ... } In the block, the Elementor widget and the Divi module, you can also change the appearance in their design settings.

How can I send the status emails to multiple addresses?

Enter several email addresses, separated by commas, in the email field of the status check. Example: webmaster@example.org,admin@example.org,dev@example.org

Why don't I receive emails from the status check?

The status check runs at the selected interval and only sends an email if at least one check has failed. If you still do not receive any emails, there may be the following reasons:

  • The email ended up in your spam folder. Please check your spam folder and add the sender address to your contacts, so future emails do not end up in spam.
  • You have disabled the WordPress cron in the wp-config.php. Please make sure that a server-side cron job is set up and working.
  • You use a caching plugin. Without a server-side cron job, WordPress checks for pending tasks on every page load. If the page is delivered from the cache, this check does not happen, and the cron job is not triggered.
  • Your website has only a few visitors, with long gaps between visits. In this case, the WordPress cron is rarely triggered.
We therefore recommend:
  • Set up a server-side cron job.
  • Add the sender address to your contacts.

What does the status check check on the website?

The status check loads the home page like a visitor without consent and checks whether the opt-out script is loaded (and not removed or delayed by an optimization plugin), and whether Google Analytics is loaded with the measurement ID of the settings. If Google Analytics is loaded only after the consent or by the Google Tag Manager, it can not be found in the HTML. This is shown as an information, not as an error. If the website is protected with a password by the server (HTTP basic authentication), e.g. a staging website, enter the access data in the settings of the status check.

Can I check the status with WP-CLI, in the Site Health or for all sites of a multisite network?

Yes. wp gaoo status shows the result of the status check, wp gaoo status --run runs it first. The command fails if a check failed, so it can be used for a monitoring. More commands:

  • wp gaoo settings export [<file>] and wp gaoo settings import <file> [--yes]: export and import of the settings, like on the settings page.
  • wp gaoo network status [--status=failed] [--format=json]: the status of all sites of a multisite network. The command fails if a check of a site failed.
  • wp gaoo network check [--site=<id>]: starts the check of all sites or of one site in the background.
The result is also shown in the Site Health of WordPress (Tools > Site Health), and in a multisite network the network admin shows the status of all sites (Network Admin > Settings > GA Opt-Out).

Can an uptime monitoring check the status (REST API)?

Yes. In the settings of the status check, create the status URL. It returns the result of the last status check as JSON: https://example.org/wp-json/gaoo/v1/status?token=TOKEN

  • HTTP status 200 if no check failed, 503 if at least one check failed, 403 if the token is wrong. You can create a new URL (the old one stops working) or disable it at any time.
  • The token can also be sent as header X-GAOO-Token instead of the parameter token.
  • The texts are English by default. With the parameter lang (e.g. lang=de or lang=de_DE) they are translated, if the language is installed on the website, otherwise they stay English.
  • status is ok or failed, total, passed, failed, unknown and info are the number of checks.
  • Every check has an id, which does not depend on the language, a label (translated text) and a result: passed, failed, unknown (not checked yet) or info (only an information, not an error).
  • last_check and next_check are in UTC (ISO 8601).
Example: {"status":"failed","total":8,"passed":6,"failed":1,"unknown":0,"info":1,"checks":[{"id":"opt_out_enabled","label":"Opt-Out Enabled","result":"passed"},{"id":"shortcode","label":"Shortcode found on the page","result":"failed"}, ...],"last_check":"2026-10-28T06:00:00+00:00","next_check":"2026-10-29T06:00:00+00:00","language":"en_US"} IDs of the checks: opt_out_enabled, measurement_id, shortcode, privacy_page_link, page_accessible, cronjob, website_check (only if the website could not be loaded), opt_out_script and google_analytics. Own checks of the filter gaoo_status_checks: the key id is optional, without it they get custom_1, custom_2 etc. Set an ID if you evaluate the check in your own code, because these numbers change when checks are added. The ID is unique: if several checks have the same ID, only the last one is shown, at the place of the first one. So an existing check can also be replaced. Set up the monitoring:
  • UptimeRobot, Better Stack, Uptime Kuma etc.: create an HTTP(S) monitor with the status URL. It reports an error if the HTTP status is not 200.
  • If your monitoring service can not check the HTTP status, use a keyword monitor with the keyword "status":"ok".
  • An interval of one hour is enough. The status check itself runs daily, weekly or monthly, or with "Check now".
Multisite network: in the network admin (Network Admin > Settings > GA Opt-Out) you can create one status URL for all sites, https://example.org/wp-json/gaoo/v1/network?token=TOKEN. It returns the HTTP status 503 if a check of a site failed, the number of sites per status (ok, failed, not_checked, inactive) and each site with the IDs of the failed checks. With the parameter status (e.g. status=failed) only these sites are listed.

Can the result be sent to Slack, Microsoft Teams or Discord (webhook)?

Yes. Enable "Use webhook" in the settings of the status check, enter the webhook URL and select the format. While the webhook is disabled, its fields are hidden and the URL is kept.

  • Slack, Mattermost, Google Chat: create an "Incoming Webhook".
  • Microsoft Teams: create a workflow "Post to a channel when a webhook request is received".
  • Discord: create a webhook in the settings of the channel (Integrations).
  • JSON for n8n, Make, Zapier or an own script: the same data as the REST API, with the name and URL of the website.
In a multisite network, the network admin (Network Admin > Settings > GA Opt-Out) can set one webhook for all sites. It gets the result of the status check of every site with the name and URL of the site, "Send test" sends the status of all sites. The webhooks of the sites work independently of it. The result is sent if a check failed, or optionally after every check. "Send test" sends the result of the last check to test the URL. The webhook URL is secret, so it is not exported. For security, the webhook can not reach addresses of the local network, this can be allowed with the filter http_request_host_is_external.

Can I transfer the settings to other websites?

Yes. With "Import / export" on the settings page, the settings are downloaded as JSON file and imported on another website. The privacy policy page, the access data for the check of the website and the webhook URL are not exported. In a multisite network, the network admin (Network Admin > Settings > GA Opt-Out) can transfer the settings of one site to all other sites, and new sites can get the settings of a site automatically. The source and code of Google Analytics, the privacy policy page, the access data, the email addresses and the webhook of each site are kept.

Can I hide the settings from site admins in a multisite network?

Yes. In the network admin (Network Admin > Settings > GA Opt-Out, tab "Settings"), "Hide the settings page" hides the settings page for site admins, so only super admins can change the settings. The site admins still see the dashboard widget and can run the check, but without links to the settings. With "Hide the dashboard widget", the site admins do not see the status check in the dashboard. Both options work independently, super admins always see everything.

How do I use the plugin with Google Tag Manager?

The opt-out cookie is set according to Google's specifications, so Google Tag Manager (GTM) usually does not need to be adjusted. However, if you want to prevent the Google Analytics code from loading at all, GTM must check whether the cookie or the local storage entry is set. Based on this, GTM can decide whether to load the code. If there is no cookie or local storage entry, or if its value is "false", the visitor has not opted out. The visitor has only opted out if the value is "true". Specific cookie for your measurement ID: ga-disable-G-XXXXXXXXXX Generic cookie: ga-opt-out Specific local storage entry: ga-disable-G-XXXXXXXXXX Generic local storage entry: ga-opt-out

Does the opt-out work with the Google Consent Mode?

Yes. Enable "Google Consent Mode" in the settings "Status" (it is disabled by default). Then the opt-out also denies the consent analytics_storage, when the link is clicked and on every page load of a visitor who has opted out. So the opt-out also works, if Google Analytics is loaded by the Google Tag Manager or with another measurement ID. On the opt-in, the consent of the cookie banner applies again after the next page load.

Liability / Disclaimer

You use this plugin at your own risk. As the website operator, you are responsible for making sure that the plugin works on your website. Among other things, check whether a cookie in the format ga-disable-G-XXXXXXXXXX is set after clicking the link. For Google Tag Manager, an additional cookie named "ga-opt-out" is set.

更新日志:

2.7.1 2.7 2.6 2.5 2.4 2.3 2.2 2.1 2.0 1.9 1.8 1.7 1.6 1.5 1.4 1.3 1.2 1.1 1.0