Installing UserReport script on website

In order for UserReport to work on your website you need to install the code snippet on your website. You get a unique code snippet each time you add a website to your account. The script is sent to you by email, but can also be found in the settings menu under website details in your UserReport account.

The UserReport script looks something like this:

<script type="text/javascript">
var _urq = _urq || [];
_urq.push(['initSite', '18454249-5a48-4e0a-b241-c648f8c540XX']);
(function() {
var ur = document.createElement('script'); ur.type = 'text/javascript'; ur.async = true;
ur.src = ('https:' == document.location.protocol ? 'https://cdn.userreport.com/userreport.js' : 'http://cdn.userreport.com/userreport.js');
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ur, s);
})();
</script>

You will have to paste the script into the template of every page on your site right above the closing html </head> tag. It is very simple, if you know how to work with HTML and templating. On most websites you just have to paste the script into one single template in order for the script to appear on all pages of the website - much like it's the case with Google Analytics.

Example - no UserReport script installed

<html>
  <head>
  <title>Title of my website</title>
  </head>
  <body>
    Content of my website
  </body>
</html>

Example - with UserReport script installed

<html>
  <head>
  <title>Title of my website</title>
    <script type="text/javascript">
    var _urq = _urq || [];
    _urq.push(['initSite', '18454249-5a48-4e0a-b241-c648f8c540XX']);
    (function() {
    var ur = document.createElement('script'); ur.type = 'text/javascript'; ur.async = true;
    ur.src = ('https:' == document.location.protocol ? 'https://cdn.userreport.com/userreport.js' : 'http://cdn.userreport.com/userreport.js');
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ur, s);
    })();
    </script>
  </head>
  <body>
    Content of my website
  </body>
</html>

It is important to add the script to all pages of your website. If you are using templates or "includes" in your webdesign, it is recommended that the script is added in this template.

Note: If you are note able to place the UserReport script in the <HEAD> section of the website, you may place it in the <BODY> section instead.

Test it: It's very easy to test if your implementation works! Simply put ?__urp=test_invite after your website URL in the browser - like http://www.mywebsite.com/?__urp=test_invite

This will open your website and force the survey to appear for testing purposes - if you have implemented the script correctly. Please note that the survey runs in demo-mode when forcing it to appear using this method. This means that answer won't be saved.

Attachments

Comments

  • Avatar
    Jérémy FRERE

    By the way here's a question on StackOverflow about this particular issue : http://stackoverflow.com/questions/27973980/userreport-and-turbolinks-how-to-make-js-turbolinks-compatible

    I added a little bounty on it to help with the motivation ... :p

  • Avatar
    Jérémy FRERE

    Hi there,

    Same as @Yosriady, I can't get it to work with Turbolinks enabled in a Rails app.

    For now I disabled Turbolinks but this is clearly not ideal.

    Do you plan on supporting it ?

    Here's a workaround someone provided to make GoogleAnalytics work with Turbolinks. Maybe you could get some inspiration from it : https://gist.github.com/jerefrer/d2c8d5a1eaead545e624

  • Avatar
    Jesper Hansen

    Hi Mitch.

    Thanks for pointing out that typo. I've corrected this in the article.

    Kind regards,
    Jesper Hansen, UserReport

  • Avatar
    Yosriady

    Hi Uffe,

    This don't seem to work for Rails Turbolinks sites. I have a working implementation using UserVoice which is similar to the following:

    $(document).on("page:change", function() {
    _urq = window._urq || [];(function() {var ur = document.createElement('script'); ur.type = 'text/javascript'; ur.async = true;
    ur.src = '//cdn.userreport.com/userreport.js';var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ur, s)
    })();
    _urq.push(['initSite', '']);
    });

    However, the embed only appears on a full page reload.

  • Avatar
    Mitch Marston

    Hi Uffe,

    I think you have a typo in this manual.

    It says "You will have to paste the script into the template of every page on your site right above the html tag." though it should be either below the html tag or above the html tag.

    If it's placed above the tag it won't be in the section of the page.

  • Avatar
    Mischa Schindowski

    Hi UserReport

    Is there any possibility to run UserReport together with turbolinks?

    I've tried several things and also analyzed the userreport.js. I think what we need is a function to re-initiate the UserReport script. If you compare it to Google Analytics you can manually force a pageview:

    ga('send', 'pageview', '#{request.path}');

    The main problem is because turbolinks just replaces the content within the body-tag during a click. So the browser doesn't recognize a real page load. Maybe there are other technologies, which need a manual re-initialization.

    I've tried _bvt.Setup(); or _bvt.initSite('ID'); without any luck.

    Would be great to have such a method.

    Kind regards,

    Mischa

    Edited by Mischa Schindowski
  • Avatar
    Mischa Schindowski
    Edited by Mischa Schindowski
Powered by Zendesk