Filter whether a UTM value is valid for reporting purposes. This allows custom validation logic for UTM parameter values.
Alpha Insights validates UTM values before using them in reports. This filter allows you to add custom validation logic to determine if a specific UTM value should be included in reporting data.
File: includes/functions/wpd-report-functions.php
Function: wpd_is_valid_reporting_utm_value()
Line: ~129
| Parameter | Type | Description |
|---|---|---|
| $valid | bool | Whether the value is valid (default: true if value passes basic validation) |
| $value | string | The UTM value to validate |
Type: bool
Description: True if valid, false to exclude from reporting
Before this filter runs, Alpha Insights checks:
add_filter( 'wpd_ai_is_valid_reporting_utm_value', 'exclude_test_values', 10, 2 );
function exclude_test_values( $valid, $value ) {
// Exclude values containing 'test' or 'debug'
if ( stripos( $value, 'test' ) !== false || stripos( $value, 'debug' ) !== false ) {
return false;
}
return $valid;
}
add_filter( 'wpd_ai_is_valid_reporting_utm_value', 'require_alphanumeric', 10, 2 );
function require_alphanumeric( $valid, $value ) {
// Only allow alphanumeric characters, hyphens, and underscores
if ( ! preg_match( '/^[a-zA-Z0-9_-]+$/', $value ) ) {
return false;
}
return $valid;
}
add_filter( 'wpd_ai_is_valid_reporting_utm_value', 'block_suspicious_chars', 10, 2 );
function block_suspicious_chars( $valid, $value ) {
// Block HTML/script injection attempts
if ( preg_match( '/[<>"\']/', $value ) ) {
return false;
}
// Block SQL injection patterns
if ( stripos( $value, 'union' ) !== false || stripos( $value, 'select' ) !== false ) {
return false;
}
return $valid;
}
add_filter( 'wpd_ai_is_valid_reporting_utm_value', 'validate_whitelist', 10, 2 );
function validate_whitelist( $valid, $value ) {
// Define allowed values (e.g., for utm_source)
$allowed_sources = array( 'google', 'facebook', 'email', 'direct', 'organic' );
// Only validate if we're checking a source value
// Note: This filter doesn't know the key, so use with caution
if ( ! in_array( strtolower( $value ), $allowed_sources ) ) {
// For this example, we'll be lenient and only block obvious invalid values
// In practice, you'd want to use wpd_ai_is_valid_reporting_utm_key_value_pair instead
return $valid;
}
return $valid;
}
add_filter( 'wpd_ai_is_valid_reporting_utm_value', 'enforce_minimum_length', 10, 2 );
function enforce_minimum_length( $valid, $value ) {
// Require values to be at least 3 characters (default is 2)
if ( strlen( $value ) < 3 ) {
return false;
}
return $valid;
}
wpd_is_valid_reporting_utm_value() - Check if UTM value is validwpd_is_valid_reporting_utm_key() - Check if UTM key is validwpd_is_valid_reporting_utm_key_value_pair() - Check if key-value pair is validadd_filter( 'wpd_ai_is_valid_reporting_utm_value', 'debug_utm_value_validation', 999, 2 );
function debug_utm_value_validation( $valid, $value ) {
if ( ! $valid ) {
error_log( sprintf(
'Alpha Insights: Excluded UTM value: %s',
$value
) );
}
return $valid;
}