Advanced widget embed usage
Tero Lindeman
Last Update 18 saat önce
When embedding a widget on a webpage it is possible to give additional parameters that alter the widget behavior. This makes it possible to reuse the same widget to display a different set of reviews.
Reusing the widget will reduce manual work when embedding widgets on different pages to show reviews for different products or locations.
The filter parameters are simply appended after the widget ID in the script URL or in the data-trustmary-widget attribute in the <div> embed. See below for examples.
The parameter values have to be encoded in case they contain special characters.
Non-coder instructions & real-life example
Have more than a dozen review connections or locations? You might want to consider using our API for managing review connections (developers) to automate this for you.
Steps for manual setup
- Import review connections (Google, Booking.com, TripAdvisor,...)
- Give each review connection a unique short name in advanced settings
4. Copy code and add ?connection=[short-name]
If short names are called mono-sushi and nanapo-sushi
5. Go to CMS and paste code with short-name
Case Sushi Helsinki
Currently, Sushi Helsinki has
- Dozens of sushi restaurants with unique landing pages
- Imported Google reviews for each location + gave them a short name
- One widget was added to multiple landing pages and filtered with review connections
Mono-sushi
Nanapo Sushi
If the site owner wants to update the style of widgets, they only need to modify one widget in Trustmary.
Once they save changes in the widget editor, all of the dozens of widgets will automatically be updated without touching the code again.
This was just one simple use case, but let's go over some more in detail.
Changing widget content
It is possible to change the content text for the widget by using parameters.
Change widget title field
The widget title field used by some widget templates can be overridden with the title parameter:
If you are using the div embedding method this is equal to the above:
Change the product name field in structured data
If Schema.org structured data is included with the widget it might be useful to set the productName field to reflect the content of the widget. Especially, when listing reviews for a single business location or a product, the productName field should refer to that item instead of the whole company. Use the productName parameter to change the product name in the structured data:
Filtering reviews with parameters
When embedding a widget on a webpage it is possible to give additional parameters that alter the widget behavior. This makes it possible to reuse the same widget to display a different set of reviews.
Reusing the widget will reduce manual work when embedding widgets on different pages to show reviews for different products or locations.
The filter parameters are simply appended after the widget ID in the script URL or after the data-trustmary-widget attribute in the <div> embed. See below for examples.
Filter by review connection
It is possible to display only reviews that have been imported from a specific review connection (Google, Facebook, Tripadvisor, etc.).
Here are some example use cases:
- You have imported reviews from multiple review sources but each are for a different location.
The above will display only reviews that have been imported from the review connection you have given the short name of "my-connection". Multiple connections can be specified as a comma-separated list:
A wildcard can be used to select all connections with a matching short name. In the below example all review connections with a short name that starts with "helsinki-" are selected:
As with any other parameter, it is possible to use connection with the div embeds:
Custom rules (contact and survey fields)
Custom rules can be used to filter by contact or survey fields.
Some example use cases:
- You have multiple business locations and your website has separate subpages for each location. It is possible to use the location as a parameter to display just the reviews for that location.
- You want to display reviews from a subset of customers that e.g. bought a specific product.
For example, if you want to display reviews for your Helsinki location, and you have collected the survey answers so that the p1 segment is set to the location name, the filter can be set as below:
Available fields for surveys:
- survey.source: the source URL for a survey as automatically set by the widget
- survey.p1–survey.p20: the segmentation parameters as given as the form URL query parameters
Learn more about segmentation with parameters here.
You can also use the contact's custom fields. If you have stored the customer's primary location as the field LOCATION, you can use the following parameters:
The parameters given will be appended to the rules you might have set in the widget editor. E.g. if you have set a custom filter to display only reviews with five stars, adding a p1 as a parameter will display only reviews with five stars that also have p1 set as the given value.
- contact.field_<FIELDNAME>: a custom field as set in contact details.