Improve cross-domain tracking and add "Always" script category
Move linker config into gtag('config') call with accept_incoming and
decorate_forms for reliable cross-domain linking. Capture _gl parameter
in sessionStorage to preserve attribution across navigation. Add
referrer-based attribution replay fallback so GA4 reports source/medium
instead of (not set) when UTMs are absent. Add "Always" script category
that executes without waiting for consent.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -97,7 +97,7 @@ class ATT_Consent_Scripts_Manager {
|
||||
global $wpdb;
|
||||
$table = self::table_name();
|
||||
|
||||
$allowed_categories = array( 'functional', 'analytics', 'marketing' );
|
||||
$allowed_categories = array( 'always', 'functional', 'analytics', 'marketing' );
|
||||
$allowed_placements = array( 'head', 'footer' );
|
||||
$allowed_statuses = array( 'active', 'inactive' );
|
||||
|
||||
@@ -150,6 +150,7 @@ class ATT_Consent_Scripts_Manager {
|
||||
public static function get_scripts_for_frontend() {
|
||||
$scripts = self::get_scripts();
|
||||
$grouped = array(
|
||||
'always' => array( 'head' => array(), 'footer' => array() ),
|
||||
'functional' => array( 'head' => array(), 'footer' => array() ),
|
||||
'analytics' => array( 'head' => array(), 'footer' => array() ),
|
||||
'marketing' => array( 'head' => array(), 'footer' => array() ),
|
||||
@@ -193,6 +194,18 @@ class ATT_Consent_Scripts_Manager {
|
||||
continue;
|
||||
}
|
||||
|
||||
// "Always" scripts execute immediately without consent gating.
|
||||
if ( 'always' === $script['category'] ) {
|
||||
if ( preg_match( '/<script[\s>]/i', $snippet ) ) {
|
||||
$output .= $snippet . "\n";
|
||||
} elseif ( preg_match( '/^\s*</', $snippet ) ) {
|
||||
$output .= $snippet . "\n";
|
||||
} else {
|
||||
$output .= '<script>' . $snippet . '</script>' . "\n";
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check if snippet contains <script> tags.
|
||||
if ( preg_match( '/<script[\s>]/i', $snippet ) ) {
|
||||
// Rewrite each <script> tag to type="text/plain" with category attribute.
|
||||
|
||||
Reference in New Issue
Block a user