You are here

hotjar.module in Hotjar 8.2

Same filename and directory in other branches
  1. 8 hotjar.module
  2. 6 hotjar.module
  3. 7 hotjar.module

Drupal Module: Hotjar.

Adds the required Javascript to all your Drupal pages to allow tracking by hotjar (https://www.hotjar.com/).

File

hotjar.module
View source
<?php

/**
 * @file
 * Drupal Module: Hotjar.
 *
 * Adds the required Javascript to all your Drupal pages to allow
 * tracking by hotjar (https://www.hotjar.com/).
 */
use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Implements hook_help().
 */
function hotjar_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    case 'hotjar.admin_settings_form':
      return t('<a href="@hotjar_url">Hotjar</a> is a new powerful way to reveal true website user behaviour and experiences in one central tool – giving you the big picture of how you can improve your site\'s UX and conversion rates. All your data is securely stored in the cloud and is accessible at lightning speed.', [
        '@hotjar_url' => 'https://www.hotjar.com/',
      ]);
  }
}

/**
 * Implements hook_rebuild().
 */
function hotjar_rebuild() {

  /** @var \Drupal\hotjar\SnippetBuilderInterface $snippet_builder */
  $snippet_builder = \Drupal::service('hotjar.snippet');
  $snippet_builder
    ->createAssets();
}

/**
 * Implements hook_page_attachments().
 *
 * Insert JavaScript to the <head> tag of the page.
 */
function hotjar_page_attachments(array &$attachments) {

  /** @var \Drupal\hotjar\SnippetAccessInterface $access */
  $access = \Drupal::service('hotjar.access');
  if (!$access
    ->check()) {
    return;
  }

  /** @var \Drupal\hotjar\SnippetBuilderInterface $snippet */
  $snippet = \Drupal::service('hotjar.snippet');
  $snippet
    ->pageAttachment($attachments);
}

/**
 * Trim lines of pages textarea.
 *
 * @param string $raw_value
 *   Raw user input.
 *
 * @return string
 *   Clean version of value.
 */
function _hotjar_clean_pages_value($raw_value) {
  $pages = trim($raw_value);
  $raw_lines = preg_split('/(\\r\\n|\\r|\\n)/', $pages);
  $lines = array_map('trim', $raw_lines);
  return implode("\n", $lines);
}

Functions

Namesort descending Description
hotjar_help Implements hook_help().
hotjar_page_attachments Implements hook_page_attachments().
hotjar_rebuild Implements hook_rebuild().
_hotjar_clean_pages_value Trim lines of pages textarea.