Skip to content

Commit 099c13f

Browse files
committed
Allow for GA Measurement IDs
1 parent a68040e commit 099c13f

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

event/listener.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,17 @@ public function validate_googleanalytics_id($event)
146146
$error = $event['error'];
147147

148148
// Add error message if the input is not a valid Google Analytics ID
149-
if (!preg_match('/^UA-\d{4,9}-\d{1,4}$/', $input))
149+
if (!preg_match('/^UA-\d{4,9}-\d{1,4}|G-[A-Z0-9]{10}$/', $input))
150150
{
151151
$error[] = $this->user->lang('ACP_GOOGLEANALYTICS_ID_INVALID', $input);
152152
}
153153

154+
// Add error message if GTAG is not selected for use with a Measurement ID
155+
if (preg_match('/^G-[A-Z0-9]{10}$/', $input) && (int) $event['cfg_array']['googleanalytics_tag'] === 0)
156+
{
157+
$error[] = $this->user->lang('ACP_GOOGLEANALYTICS_TAG_INVALID', $input);
158+
}
159+
154160
// Update error event data
155161
$event['error'] = $error;
156162
}

language/en/googleanalytics_acp.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@
4040
$lang = array_merge($lang, array(
4141
'ACP_GOOGLEANALYTICS' => 'Google Analytics',
4242
'ACP_GOOGLEANALYTICS_ID' => 'Google Analytics ID',
43-
'ACP_GOOGLEANALYTICS_ID_EXPLAIN' => 'Enter your Google Analytics ID code, e.g.: <samp>UA-0000000-00</samp>.<br /><br />Google Analytics can track your registered users across multiple devices and sessions, for a more accurate user count in your reports. To enable this enhanced functionality User ID tracking must be configured in your Google Analytics account. <a href="https://support.google.com/analytics/answer/3123666">Click for more information <i class="icon fa-external-link fa-fw" aria-hidden="true"></i></a>.',
44-
'ACP_GOOGLEANALYTICS_ID_INVALID' => '“%s” is not a valid Google Analytics ID code.<br />It should be in the form “UA-0000000-00”.',
43+
'ACP_GOOGLEANALYTICS_ID_EXPLAIN' => 'Enter your Google Analytics Tracking ID <samp>UA-000000-00</samp> or Measurement ID <samp>G-XXXXXXXXXX</samp>. Leave this field empty if you do not use Google Analytics.<br /><br />Google Analytics can track your registered users across multiple devices and sessions, for a more accurate user count in your reports. To enable this enhanced functionality User ID tracking must be configured in your Google Analytics account. <a href="https://support.google.com/analytics/answer/3123666">Click for more information <i class="icon fa-external-link fa-fw" aria-hidden="true"></i></a>.',
44+
'ACP_GOOGLEANALYTICS_ID_INVALID' => '“%s” is not a valid Google Analytics ID code.<br />It should be in the form “UA-000000-00” or “G-XXXXXXXXXX”.',
45+
'ACP_GOOGLEANALYTICS_TAG_INVALID' => '“Global Site Tag (gtag.js)” must be the selected Google Analytics Script Tag when using a Measurement ID.',
4546
'ACP_GA_ANONYMIZE_IP' => 'Turn on IP Anonymization',
4647
'ACP_GA_ANONYMIZE_IP_EXPLAIN' => 'Enable this option if you want the data collected by Google Analytics to be compliant with the EU‘s General Data Protection Regulation (GDPR). Note that enabling this option may slightly reduce the accuracy of geographic reporting.',
4748
'ACP_GOOGLEANALYTICS_TAG' => 'Google Analytics Script Tag',

0 commit comments

Comments
 (0)