Methods
executeOnUrlChange(callback, regexopt) → {void}
A JavaScript helper function that executes a callback when the URL changes, optionally matching against provided regular expression(s).
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
callback |
function
|
The function to execute when the URL changes. |
|
regex |
RegExp
|
Array.<RegExp>
|
<optional> |
(Optional) The regular expression(s) to match against the URL. The callback will be executed only if the URL matches at least one of the provided regular expressions. If not specified or null, the callback will be executed on any URL change. |
Returns:
- Type:
-
void
Example
executeOnUrlChange(() => {
console.log('URL has changed!');
}, /^https?:\/\/(www\.)?example\.com/);
mutObs(elemToObserve, option, pauseForMutations, callback)
A function that allows you to watch an element's mutations, and perform a callback function if a mutation is observed.
Parameters:
| Name | Type | Description |
|---|---|---|
elemToObserve |
string
|
node
|
A CSS selector or a node. |
option |
array
|
object
|
string
|
Pass multiple mutation observer options to be set to TRUE. The options are (case sensitive) childList, subtree, attributes, characterData, attributeOldValue, characterDataOldValue and attributeFilter. The standard MutationObserver JS Object config can be passed in here for more complex options, such as the 'attributeFilter' option, which requires an array to be passed in with it. Finally, you can pass in a single config option to be set to true as a string. |
pauseForMutations |
boolean
|
Pass in true or false if you would like the observer to pause whilst mutations are made, then re-connect once complete. Typically the observer would be paused whilst changes are made to, or inside, the element that is being observed. |
callback |
function
|
The function to run when a mutation is observed. |
onElementIsVisible(elementToCheck, callback, elementIndexopt)
A trigger which runs a callback function based on whether an element on the page has been viewed by the user.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
elementToCheck |
string
|
A CSS selector |
|
callback |
function
|
The function to run when the elementToCheck has returned true |
|
elementIndex |
string
|
<optional> |
If there are multiple of the same CSS selectors available on the page, specify the index number of the element you want to target |
onMouseLeave(conditions, callback, thresholdopt)
Function to initialise the mouse leave detection function.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
conditions |
string
|
Conditions to be met for the function to run. Has to return true. |
||
callback |
function
|
The function to run when the conditions have returned true |
||
threshold |
number
|
<optional> |
5 |
Threshold set for mouse y position |
onNoInteraction(callback, timeopt)
Call a function after there has been no interaction for a set period
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
callback |
function
|
The function to run after no interaction |
||
time |
function
|
<optional> |
7000 |
How long before calling the callback in milliseconds |
pollElements(callback, arg)
A poller which allows you to wait for multiple elements to exist before running a callback function.
Parameters:
| Name | Type | Description |
|---|---|---|
callback |
function
|
The function to run when the element(s) have been found |
arg |
string
|
Pass multiple elements that you want to poll for. There is no limit to the amount of elements you can check, but the more you check for, the longer the poller will take to run. |
pollFor(assertion, onSuccess, timeoutopt, onTimeoutopt)
A poller which allows you to wait for specific criteria before running a callback function.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
assertion |
string
|
function
|
array
|
Either a CSS selector, a function that returns a boolean, or an array of functions |
||
onSuccess |
pollForCallback
|
The function to run when the assertion has returned true |
||
timeout |
number
|
null
|
<optional> |
10 |
How many seconds should we poll for before giving up |
onTimeout |
pollForCallback
|
null
|
<optional> |
An optional function to run when polling has timed out |
sendEvent(gaPayload)
Function for GA tracking. Use ga.sendEvent() to call the function.
Parameters:
| Name | Type | Description | |||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
gaPayload |
Object
|
Used to pass through specific properties for the GA tracking
|
tag(name)
Function for HJ tagging. Use hotjar.tag() to call the function.
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string
|
Name of tag to pass through |
toArray(x)
Function to convert non-compatible array format to a standard array for IE compatibility
Parameters:
| Name | Type | Description |
|---|---|---|
x |
array
|
The array (nodelist, HTMLCollection etc) to be converted to a standard array (e.g. document.querySelectorAll(".all-my-selectors")) |
trigger(name)
Function for HJ triggering. Use hotjar.trigger() to call the function.
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string
|
Name of trigger |