To add Usersnap to a server-rendered site, save the Usersnap space snippet in a template partial, load your API key from an environment variable, and include the partial just before the closing </body> tag. Because the partial runs on your server, you can add conditions (for example, show the widget only to logged-in users) and pass backend data such as the user ID or plan into the widget. Below are examples for PHP, Python (Jinja2 and Django), and Ruby on Rails.
If you don’t need any of that, the simplest route is to copy the snippet from your project’s Publish tab and paste it into your site, as described in installation via HTML. There are also guides for WordPress and Google Tag Manager.
The Usersnap snippet
Every example below uses the same space (global) snippet. Copy yours from Configure, Publish in your Usersnap project. It looks like this:
<script>
window.onUsersnapLoad = function(api) {
api.init();
window.Usersnap = api;
}
var script = document.createElement('script');
script.defer = 1;
script.src = 'https://widget.usersnap.com/global/load/YOUR_API_KEY?onload=onUsersnapLoad';
document.getElementsByTagName('head')[0].appendChild(script);
</script>
Each snippet belongs to one space. Read more about the global snippet.
Include Usersnap with PHP
Save the snippet in a file called usersnap.inc.php and read the API key from an environment variable:
<script>
window.onUsersnapLoad = function(api) {
api.init();
window.Usersnap = api;
}
var script = document.createElement('script');
script.defer = 1;
script.src = 'https://widget.usersnap.com/global/load/<?= htmlspecialchars(getenv('USERSNAP_API_KEY')) ?>?onload=onUsersnapLoad';
document.getElementsByTagName('head')[0].appendChild(script);
</script>
Then include it in your footer template, with any condition you need:
<?php if (isset($_SESSION['user_id'])) { include 'usersnap.inc.php'; } ?>
Include Usersnap with Python (Jinja2 or Django)
Save the snippet as usersnap.html in your templates folder and pass the API key from your settings or environment into the template context:
script.src = 'https://widget.usersnap.com/global/load/{{ usersnap_api_key }}?onload=onUsersnapLoad';
Include it in your base template before the closing body tag:
{% if user.is_authenticated %}{% include "usersnap.html" %}{% endif %}
Include Usersnap with Ruby on Rails
Save the snippet as a partial called _usersnap.html.erb and load the key from an environment variable:
script.src = 'https://widget.usersnap.com/global/load/<%= ENV["USERSNAP_API_KEY"] %>?onload=onUsersnapLoad';
Render the partial in your layout, just before the closing body tag:
<%= render "usersnap" if user_signed_in? %>
Pass backend data into the widget
Server-side templates are a good place to identify the user and add context to every report. Pass user details to api.init and they show up on each feedback item, so your team knows who reported what. See user identification:
api.init({
user: {
userId: '123456',
email: 'jane@example.com',
plan: 'Enterprise'
}
});
You can also attach custom data, such as your app version or environment, with api.init({ custom: { appVersion: '1.0.1', environment: 'production' } }). Render these values from your backend the same way as the API key.
Include Usersnap with any other framework
Template includes exist in nearly every web framework. Save the snippet as a partial, inject the API key and any user data from the server, and include it before the closing body tag. Single-page apps work a little differently, see the guides for React, npm, and single-page applications.
Usersnap is a product evidence platform that connects what people say, what you build, and how it lands. Try Usersnap free, no credit card needed.
Turn scattered customer signals into decisions you can defend
Support tickets, sales calls, in-app comments, surveys and NPS land in one shared view automatically, tagged back to the source the moment they arrive.
- See the pattern across channels, without anyone stitching tools together first.
- Start from a scored opportunity your team can act on the same day.
- Every claim traces back to a real comment, so the roadmap holds up to the follow-up question.
- One platform replaces three to five point tools, with a single data agreement and one security review.
One snippet connects Usersnap to your stack and it is live in minutes. Start free or get a custom trial with our team.