| 开发者 | schweizersolutions |
|---|---|
| 更新时间 | 2026年10月30日 17:34 |
| 捐献地址: | 去捐款 |
| PHP版本: | 7.4 及以上 |
| WordPress版本: | 7.1 |
| 版权: | GPLv2 or later |
| 版权网址: | 版权信息 |
[ga_optout] with attributes for individual texts and the behavior.wp gaoo status shows the result of the status check with WP-CLI, wp gaoo status --run runs it first. The command fails if a check failed, so it can be used in a monitoring script.lang.wp gaoo network status and wp gaoo network check show and start the check of all sites, wp gaoo settings export and wp gaoo settings import transfer the settings, e.g. in a deployment script.Plugins > Add New Plugin.Opt-Out for Google Analytics.opt-out-for-google-analytics to the /wp-content/plugins/ directory of your WordPress installation.Settings > GA Opt-Out.[ga_optout], the block, the Elementor widget or the Divi module "Opt-Out for Google Analytics". Done!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.
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
Yes. The plugin also works if the tracking code was added to the theme manually or with another plugin.
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
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.
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".
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.
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.
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; } `
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]');
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.
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.
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.
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
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 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.
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.Tools > Site Health), and in a multisite network the network admin shows the status of all sites (Network Admin > Settings > GA Opt-Out).
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
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.X-GAOO-Token instead of the parameter token.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.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).{"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:
"status":"ok".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.
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.
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.
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.
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.
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
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.
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.