Hello! How can we help?

Browse the Trustpilot Support Center to find info on Google Seller Ratings, Rich Snippets, TrustBoxes, Product reviews, plus how-to guides for editing your reviews and account settings

How to use TrustBoxes in single-page applications

To load a TrustBox programmatically in a single-page app, you will need to:

  • Make sure the TrustBox script is inserted in your app
  • Make sure the TrustBox HTML snippet is inserted in your app
  • Add a reference to the TrustBox HTML element in JavaScript. For example, you can add a custom id attribute on the <div>:

<div id="trustbox" class="trustpilot-widget" [ long list of data attributes...]> <a href="https://www.trustpilot.com/review/example.com" target="_blank">Trustpilot</a> </div>

Then, you can call your reference this way:

var trustbox = document.getElementById('trustbox');

Finally, use the window.Trustpilot.loadFromElement method provided by the TrustBox script to load your TrustBox:

window.Trustpilot.loadFromElement(trustbox);

Comments

4 comments

  • Avatar

    Thanks a lot!)

  • Avatar

    You're welcome, thanks for the feedback!

  • Avatar

    for anyone reading this and using React, you need to place the HTML tag on the page then within your `componentDidMount`, you place the trustbox and window.Truspilot... script.

    and of course, make sure the tp script has already been loaded within the of your site

    @trustpilot, the directions you provided aren't as clear as they could be. you may want to update this and break it out for react, angular, vanilla JS, etc.

  • Avatar

    Hi Ben,

    Thanks for your feedback, we've passed it on to our development team!

    Beatrice
    Trustpilot

Please sign in to leave a comment.