Skip to main content
The @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

Call init 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 init doesn’t need to run again per route. A second init logs a warning and does nothing; to start over, call destroy() first.
  • React strict mode. In development, React mounts, unmounts and mounts an effect again. The init and destroy pair in the examples handles that cycle.
  • Server rendering. Importing the package on the server is safe, and init does nothing where there is no window. Call it from client-only code such as useEffect, onMounted, onMount or a .client plugin.
  • 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.

Open a survey from your code

When a website survey uses the Custom event trigger, your app opens it by sending the event:
An event sent before the widget is ready is kept and checked against the surveys for 10 seconds after the widget becomes ready. Every method is described in the SDK reference.