Add cross-domain tracking support (v1.2.0)

Add linker domains setting to Advanced tab for cross-domain measurement.
Outputs gtag('set','linker') before config call so GA4 appends the _gl
parameter to links pointing at configured domains.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-04 13:33:30 +00:00
parent 2294c8eda7
commit 868ed867e2
5 changed files with 41 additions and 5 deletions

View File

@@ -226,6 +226,18 @@ class ATT_Consent_Admin {
if ( $settings['wait_for_update'] > 10000 ) {
$settings['wait_for_update'] = 10000;
}
// Cross-domain tracking: sanitize each domain line.
$raw_domains = $_POST['cross_domain_domains'] ?? '';
$lines = array_filter( array_map( 'trim', explode( "\n", $raw_domains ) ) );
$clean = array();
foreach ( $lines as $line ) {
$domain = sanitize_text_field( $line );
if ( '' !== $domain ) {
$clean[] = $domain;
}
}
$settings['cross_domain_domains'] = implode( "\n", $clean );
break;
}

View File

@@ -60,9 +60,10 @@ class ATT_Consent {
'cat_marketing_desc' => 'These cookies are used to deliver advertisements relevant to you.',
// Advanced.
'url_passthrough' => true,
'ads_data_redaction' => true,
'wait_for_update' => 500,
'url_passthrough' => true,
'ads_data_redaction' => true,
'wait_for_update' => 500,
'cross_domain_domains' => '',
);
/**

View File

@@ -57,6 +57,14 @@ class ATT_Consent_Frontend {
'tracking_mode' => $s['tracking_mode'],
);
// Cross-domain tracking domains.
if ( ! empty( $s['cross_domain_domains'] ) ) {
$domains = array_filter( array_map( 'trim', explode( "\n", $s['cross_domain_domains'] ) ) );
if ( ! empty( $domains ) ) {
$config['linker_domains'] = array_values( $domains );
}
}
// In basic mode, pass the tracking snippet for deferred injection.
if ( 'basic' === $s['consent_mode'] ) {
$config['tracking_snippet'] = $this->get_tracking_snippet();
@@ -107,6 +115,7 @@ wait_for_update:c.wait_for_update||500
});
window.attCCHasConsent=false;
}
if(c.linker_domains&&c.linker_domains.length){g('set','linker',{'domains':c.linker_domains});}
if(!sessionStorage.getItem('att_cc_attr')){
var p=new URLSearchParams(window.location.search);
var a={