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

@@ -55,6 +55,20 @@ if ( ! defined( 'ABSPATH' ) ) {
</p> </p>
</td> </td>
</tr> </tr>
<tr>
<th scope="row">
<label for="cross_domain_domains"><?php esc_html_e( 'Cross-Domain Tracking', 'att-consent' ); ?></label>
</th>
<td>
<textarea name="cross_domain_domains" id="cross_domain_domains" rows="4" class="large-text code"><?php echo esc_textarea( $settings['cross_domain_domains'] ); ?></textarea>
<p class="description">
<?php esc_html_e( 'Enter one domain per line for cross-domain measurement. The linker parameter will be appended to URLs pointing to these domains, allowing unified user tracking across sites.', 'att-consent' ); ?>
</p>
<p class="description">
<?php esc_html_e( 'Example: bookingengine.myguestdiary.com', 'att-consent' ); ?>
</p>
</td>
</tr>
</table> </table>
<h2><?php esc_html_e( 'Google Consent Mode v2 Signal Reference', 'att-consent' ); ?></h2> <h2><?php esc_html_e( 'Google Consent Mode v2 Signal Reference', 'att-consent' ); ?></h2>

View File

@@ -3,7 +3,7 @@
* Plugin Name: ATT Consent * Plugin Name: ATT Consent
* Plugin URI: https://github.com/att-consent/att-consent * Plugin URI: https://github.com/att-consent/att-consent
* Description: Google Consent Mode v2 cookie consent with session attribution preservation, custom script management, and full gtag.js/GTM support. * Description: Google Consent Mode v2 cookie consent with session attribution preservation, custom script management, and full gtag.js/GTM support.
* Version: 1.1.0 * Version: 1.2.0
* Requires at least: 6.0 * Requires at least: 6.0
* Requires PHP: 7.4 * Requires PHP: 7.4
* Author: ATT Consent * Author: ATT Consent
@@ -18,7 +18,7 @@ if ( ! defined( 'ABSPATH' ) ) {
exit; exit;
} }
define( 'ATT_CC_VERSION', '1.1.0' ); define( 'ATT_CC_VERSION', '1.2.0' );
define( 'ATT_CC_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); define( 'ATT_CC_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
define( 'ATT_CC_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); define( 'ATT_CC_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
define( 'ATT_CC_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); define( 'ATT_CC_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );

View File

@@ -226,6 +226,18 @@ class ATT_Consent_Admin {
if ( $settings['wait_for_update'] > 10000 ) { if ( $settings['wait_for_update'] > 10000 ) {
$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; break;
} }

View File

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

View File

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