@usertick/snippet package runs the same widget as the script tag, started from your app’s code instead of a tag in the page. Both follow client-side route changes, so a survey targeted at /pricing also opens after the app navigates to /pricing.
Install the package
Initialize the widget
Callinit once when the app starts, with the site ID from Settings → Sites (the file name in the site’s install code):
init loads the site’s code file from cdn.usertick.com, which carries the site’s live surveys, so nothing else needs to be configured. When that file can’t be loaded, the package uses the copy it saved in the browser during the last 24 hours and keeps trying in the background.
Check now in Settings → Sites looks for the script tag in the HTML of the home page, so it can’t see a package that loads from JavaScript. To connect the site, also add the script tag to the home page. The tag and the package share one widget on the page. See Check the install.
Framework examples
Single page app behavior
- Initialize once. The widget follows route changes on its own, so
initdoesn’t need to run again per route. A secondinitlogs a warning and does nothing; to start over, calldestroy()first. - React strict mode. In development, React mounts, unmounts and mounts an effect again. The
initanddestroypair in the examples handles that cycle. - Server rendering. Importing the package on the server is safe, and
initdoes nothing where there is nowindow. Call it from client-only code such asuseEffect,onMounted,onMountor a.clientplugin. - Both installs on one page. When the script tag and the package are both on a page, the second copy finds the first and stays idle, so surveys never show twice.