Giter Club home page Giter Club logo

nuxt-trustbox-module's Introduction

TrustBox module for Nuxt

npm (scoped with tag) npm

A NuxtJS module thats injects Trustpilot TrustBox code and provide a <trustbox /> component

CodeSandbox: CODE REPRODUCTION | FULL PAGE EXAMPLE

Why this package/module?

Because I use Nuxt for a lot of my projects and the classic TrustBox installation (injection of the script into the head.scripts of the nuxt.config.js configuration file doesn't work).

First I tried to create a plugin that injects the Trustpilot's script, the widget were displayed but only on the first load (SSR). When I switched between pages, if the widget was into the page, it wasn't displayed anymore because there's an initialize function into the script executed on its load.

So I had to re-execute this initialization function when a new trustbox-widget is added to the DOM and after the script was loaded 1 or more pages before. Then I decided to create the <trustbox /> component which calls the initialization function when it's mounted.

Also, as the businessunitId and businessunitName should always be the same on your site, if you want to display multiple TrustBoxes without specifying these attributes each time, I added a config file.

Table of Contents

Requirements

  • yarn
  • NuxtJS
  • NodeJS

Installation

yarn add nuxt-trustbox-module

Getting Started

Add nuxt-trustbox-module to modules section of nuxt.config.js:

{
  modules: [

    // Simple usage
    'nuxt-trustbox-module',

    // With options
    ['nuxt-trustbox-module', {
      businessunitId: 'TRUSTPILOT_BUSINESS_ID',
      businessunitName: 'TRUSTPILOT_BUSINESS_NAME',
    }],

 ]
}

Here's how to use it:

<!-- Wrapping with <client-only> (or <no-ssr>) to prevent mismatching content between server and client -->
<client-only>

    <trustbox
        template-id="my_trustbox_template_id"
        style-height="150px"
        style-width="400px" />

</client-only>

i18n Translation

It's very simple to automatically translate the TrustBox if you are using nuxt-i18n:

The key attribute is very important to refresh the component when the locale is switched.

<!-- Wrapping with <client-only> (or <no-ssr>) to prevent mismatching content between server and client -->
<client-only>

    <trustbox
      template-id="my_trustbox_template_id"
      :locale="$i18n.locales.find(l => l.code === $i18n.locale).iso"
      :key="$i18n.locale" />

</client-only>

Module options

List of possible options in the module which can be passed through the module options or by props:

Note that the options passed through nuxt.config.js are camelCase while options passed through props are kebab-case.

Option Default Required Description
businessunitId '' true Your Trustpilot Business ID, you can find it here.
businessunitName '' true Your Trustpilot Business Name/URL, it's what comes after https://trustpilot.com/review/businessunitName.
templateId '' true Template ID of the TrustBox.
styleHeight auto false Height of the TrustBox.
styleWidth 100% false Width of the TrustBox.
locale en-US false Locale to display on the TrustBox into a valid ISO format supported by Trustpilot.
theme light false Theme of the TrustBox (can be light or dark).
tags '' false Template ID of the TrustBox.
schemaType '' false Enabled SEO Rich Snippets if configured to organization.
stars '' false Specify stars to display on some widgets (example: 3,4,5).

nuxt-trustbox-module's People

Contributors

haplifeman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

nuxt-trustbox-module's Issues

Support of reviews language

The module doesn't support changing the language of reviews. Right now, the reviews are displayed in the language they were written. Attribute data-review-languages is missing.
Screenshot_4

Will it be possible to add that attirube ?

Support for Nuxt3

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
Nuxt3 with nuxt-trustbox-module currently gives locale is not defined error.

Describe the solution you'd like
Support for Nuxt3

Describe alternatives you've considered

Additional context

Trustbox code:

<client-only>
     <trustbox
                template-id="---"
                locale="nl-NL"
                style-height="150px"
                style-width="400px" />
</client-only>

Nuxt config:

[
            'nuxt-trustbox-module',
            {
                businessunitId: '-------',
                businessunitName: '---------',
                locale: 'nl-NL'
            }
        ]

The following error is produced:

ERROR [unhandledRejection] locale is not defined

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.