diff --git a/google_analytics.module b/google_analytics.module index addd4ec..0d7f87a 100644 --- a/google_analytics.module +++ b/google_analytics.module @@ -324,6 +324,26 @@ function google_analytics_page_attachments(array &$page) { $script .= 'ga("set", "anonymizeIp", true);'; } + // allow other modules to specify a content grouping for this page + $groupNames = [ + 'contentGroup1' => NULL, + 'contentGroup2' => NULL, + 'contentGroup3' => NULL, + 'contentGroup4' => NULL, + 'contentGroup5' => NULL, + ]; + + $node = $request->attributes->get('node'); + \Drupal::moduleHandler()->alter('google_analytics_content_group', $groupNames, $node); + + if ($groupNames != NULL && is_array($groupNames)) { + foreach ($groupNames as $contentGroup => $groupName) { + if ($contentGroup != NULL && !empty($contentGroup) && $groupName != NULL && !empty($groupName)) { + $script .= "ga('set', '{$contentGroup}', '{$groupName}');"; + } + } + } + if (!empty($custom_var)) { $script .= $custom_var; }