Wpd Ai Event Tracking Prevent Foreign Referrals

Alpha Insights Documentation

Docs Navigation

Filter: wpd_ai_event_tracking_prevent_foreign_referrals

When true, the event tracking REST endpoint returns 403 Forbidden for requests whose referer is from a different domain.

Description

Alpha Insights validates that the request referer matches the site in some cases. If you want to block all events that come from a different host (e.g. to prevent cross-site event injection), return true from this filter. When the referer is considered “foreign,” the API responds with a 403 and message “Forbidden request.” (code invalid_referer). Default is false.

Location

File: includes/classes/WPDAI_Woocommerce_Event_Tracking.php

Context: REST request validation when the referer host does not match the site host.

Parameters

Parameter Type Description
(none) No parameters passed. Return true to block foreign referers; false to allow.

Return

Type: bool

True to block the request (403); false to allow it (default).

Example Usage

Block events from other domains

add_filter( 'wpd_ai_event_tracking_prevent_foreign_referrals', '__return_true' );

Block only in production

add_filter( 'wpd_ai_event_tracking_prevent_foreign_referrals', 'block_foreign_referers_in_production' );
function block_foreign_referers_in_production() {
    return wp_get_environment_type() === 'production';
}

Related Filters

Got A Question?

Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
Alpha Insights

Alpha Insights

The World's Most Advanced WooCommerce Profit Reporting Engine

5/5 – Trustpilot

Alpha Insights