Add optional global gtag() exposure setting
New checkbox in General settings to conditionally expose window.gtag() for compatibility with third-party scripts (e.g. HFCM). Defaults to off, keeping only window.attCCGtag() available. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -101,6 +101,22 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row">
|
||||
<?php esc_html_e( 'Global gtag Function', 'att-consent' ); ?>
|
||||
</th>
|
||||
<td>
|
||||
<label for="expose_gtag_global">
|
||||
<input type="checkbox" name="expose_gtag_global" id="expose_gtag_global" value="1"
|
||||
<?php checked( $settings['expose_gtag_global'] ); ?>>
|
||||
<?php esc_html_e( 'Expose window.gtag() globally', 'att-consent' ); ?>
|
||||
</label>
|
||||
<p class="description">
|
||||
<?php esc_html_e( 'Enable this if other plugins or custom scripts on your site call gtag() directly (e.g. HFCM snippets). When disabled, only window.attCCGtag() is available.', 'att-consent' ); ?>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row">
|
||||
<label for="floating_widget"><?php esc_html_e( 'Floating Widget', 'att-consent' ); ?></label>
|
||||
|
||||
@@ -170,6 +170,7 @@ class ATT_Consent_Admin {
|
||||
true
|
||||
) ? $_POST['floating_widget'] : 'bottom-right';
|
||||
$settings['floating_widget_label'] = sanitize_text_field( $_POST['floating_widget_label'] ?? '' );
|
||||
$settings['expose_gtag_global'] = ! empty( $_POST['expose_gtag_global'] );
|
||||
break;
|
||||
|
||||
case 'appearance':
|
||||
|
||||
@@ -33,6 +33,7 @@ class ATT_Consent {
|
||||
'consent_expiry' => 365,
|
||||
'floating_widget' => 'bottom-right',
|
||||
'floating_widget_label' => 'Cookie Settings',
|
||||
'expose_gtag_global' => false,
|
||||
|
||||
// Appearance.
|
||||
'banner_bg_color' => '#1a1a2e',
|
||||
|
||||
@@ -72,6 +72,9 @@ var c=window.attCCConfig;
|
||||
window.dataLayer=window.dataLayer||[];
|
||||
function g(){window.dataLayer.push(arguments);}
|
||||
window.attCCGtag=g;
|
||||
<?php if ( ! empty( $s['expose_gtag_global'] ) ) : ?>
|
||||
window.gtag=g;
|
||||
<?php endif; ?>
|
||||
g('js',new Date());
|
||||
if(c.ads_data_redaction){g('set','ads_data_redaction',true);}
|
||||
if(c.url_passthrough){g('set','url_passthrough',true);}
|
||||
|
||||
Reference in New Issue
Block a user