Problem/Motivation

In order to selectively enable the Hotjar script based on if the user accepted cookies or not, we want to be able to wrap the Hotjar snippet in a function. Currently the Hotjar module has no way of altering the snippet that is output.

Proposed resolution

An alter hook on the snippet script in SnippetBuilder::buildSnippet would allow the script to be wrapped. It does mean that the alter is never called when the script is included as a Drupal attachment. The API function should document this exception.

A patch is attached that adds and documents the hook.

API changes

A new hook is added, hook_hotjar_snippet_alter(), which receives the generated Hotjar snippet script by reference.

Release notes snippet

Added a hook for altering a built Hotjar snippet.

CommentFileSizeAuthor
hotjar-snippet-alter.patch1.14 KBdennis_meuwissen

Comments

dennis_meuwissen created an issue. See original summary.

tikaszvince’s picture

Status: Active » Fixed

Hi @dennis_meuwissen,

Thank you the contribution. This feature will part of the next release.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.