Record title without theming

Created on 20 June 2025, 4 months ago

Problem/Motivation

Some theme change the title, "Title | Site Name"

The site name is not useful when reviewing analytics.

Steps to reproduce

Proposed resolution

Add the title to drupalSettings before the title is themed.

Remaining tasks

User interface changes

API changes

Data model changes

if (title) {
  _paq.push(['setDocumentTitle', title]);
}
/**
 * Implements hook_preprocess_html().
 */
function visitors_preprocess_html(array &$variables) {
  $title = '';
  if (isset($variables['head_title']['title'])) {
    $title = strip_tags((string) $variables['head_title']['title']);
  }
  elseif (isset($variables['head_title']) && is_string($variables['head_title'])) {
    $title = strip_tags((string) $variables['head_title']);
  }

  $variables['#attached']['drupalSettings']['visitors']['title'] = $title;
}
πŸ“Œ Task
Status

Active

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States bluegeek9

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024