Skip to content
Snippets Groups Projects
Commit 8b20b898 authored by Igor Biki's avatar Igor Biki
Browse files

ISTWCMS-4707: Not adding GA code to admin and default 403/404 pages.

parent 67789f0c
No related branches found
No related tags found
1 merge request!75ISTWCMS-4707 Adding config form, permissions, and route for module.
...@@ -349,8 +349,28 @@ function uw_cfg_common_page_attachments(array &$page) { ...@@ -349,8 +349,28 @@ function uw_cfg_common_page_attachments(array &$page) {
$page['#attached']['html_head'][] = [$data, 'uw-google-site-verification']; $page['#attached']['html_head'][] = [$data, 'uw-google-site-verification'];
} }
// Check if requested route is admin route. This should cover /node/1/edit,
// node/1/revisions, term/1/edit, webform results page
$skip_ga_snippet = \Drupal::service('router.admin_context')->isAdminRoute();
// When current route is not detected as admin path, check if route is
// 403 or 404. Skip injecting GA code snippets on those pages.
if (!$skip_ga_snippet) {
$route_name = \Drupal::routeMatch()->getRouteName();
// Check for default 403/404 pages. This will not cover any custom 403/404
// pages that may be webpages (e.g. /node/3).
if (in_array($route_name, ['system.403', 'system.404'])) {
$skip_ga_snippet = TRUE;
}
// Adding exception for layout builder.
elseif (preg_match('/^layout_builder\..+$/', $route_name)) {
$skip_ga_snippet = TRUE;
}
}
// Get the code from config and inject to the page. // Get the code from config and inject to the page.
if (!empty($config->get('uw_cfg_common_ga_account'))) { if (!$skip_ga_snippet && !empty($config->get('uw_cfg_common_ga_account'))) {
$code = Html::escape($config->get('uw_cfg_common_ga_account')); $code = Html::escape($config->get('uw_cfg_common_ga_account'));
$firstLetter = strtolower(substr($code, 0, 1)); $firstLetter = strtolower(substr($code, 0, 1));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment