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.
| Comment | File | Size | Author |
|---|---|---|---|
| hotjar-snippet-alter.patch | 1.14 KB | dennis_meuwissen |
Comments
Comment #3
tikaszvince commentedHi @dennis_meuwissen,
Thank you the contribution. This feature will part of the next release.