js.run_on_activity
/
Script and Style /
js.run_on_activity
By Amit Singh . Posted on August 20, 2022
Note: this is available from 3.3.1 onwards.
Title
:
js.run_on_activity
Purpose
:
This shortcode can be used to load scripts or code on any user activity to help improve the frontend performance of the site.
Syntax
:
[ js. run_ on_ activity src = '//js.hsforms.net/forms/v2.js' ]
hbspt. forms. create( {
region: "na1" ,
portalId: "19775270" ,
formId: "18456b0e-d5d4-4156-a2cc-f64a1d7cb6cd"
} ) ;
[ / js. run_ on_ activity]
Input Parameters
:
src: the src URL of the script that you want to include during the activity.
content: the script code specified here will be executed as is, and if src is specified then the content script will be executed after the script is loaded
Return Value
:
Wrapped script for execution
Example 1
:
Code
:
[ js. run_ on_ activity src = '//js.hs-scripts.com/19775270.js' / ]
Output
:
This will include the script specified by “src ” attribute when a user interacts with the browser
Example 2
:
Code
:
[ js. run_ on_ activity src = '//js.hsforms.net/forms/v2.js' ]
hbspt. forms. create( {
region: "na1" ,
portalId: "19775270" ,
formId: "18456b0e-d5d4-4156-a2cc-f64a1d7cb6cd"
} ) ;
[ / js. run_ on_ activity]
Output
:
In this example first, the src URL will be loaded and then the content script will be executed on user interaction
Example 3
:
Code
:
[ js. run_ on_ activity ]
( function( h, o, t, j, a, r) {
h. hj= h. hj|| function( ) { ( h. hj. q= h. hj. q|| [ ] ) . push( arguments) } ;
h. _ hjSettings= { hjid: 1973589, hjsv: 6} ;
a= o. getElementsByTagName( 'head' ) [ 0] ;
r= o. createElement( 'script' ) ; r. async= 1;
r. src= t+ h. _ hjSettings. hjid+ j+ h. _ hjSettings. hjsv;
a. appendChild( r) ;
} ) ( window, document, 'https://static.hotjar.com/c/hotjar-' , '.js?sv=' ) ;
[ / js. run_ on_ activity]
Output
:
In this example directly the content script will be executed after user interaction.
Last Modified By Amit Singh .