Skip to main content
All CollectionsDeveloper DocsHow-to's
How to Add the Yotpo Review Star Widget to Your Quiz Products
How to Add the Yotpo Review Star Widget to Your Quiz Products
Mark Baek avatar
Written by Mark Baek
Updated over a week ago

This guide gives instructions on how to add custom code to your quiz that will insert Yotpo's review star on-site widget to each product at the end of your quiz.

πŸ’‘ What you'll learn


πŸ’‘ Prerequisites

This guide requires access to the octane.quiz.completed[?] custom event available on Octane Plus & Enterprise plans.


Code to add the Yotpo review star on-site widget

This code block will add Yotpo's review star on-site widget to each of your quiz products regardless of the structure of your results page content.


<script>
document.addEventListener("octane.quiz.completed", function(event) {
const productTitles = document.querySelectorAll(".oct-quiz-result-item__title");
const arrayOfProductBlocks = event.detail.product_blocks;
const productIdArray = [];

function buildProductIdArray() {
for (const productBlock of arrayOfProductBlocks) {
productBlock.forEach(product => {
productIdArray.push(product.id)
});
};
};

buildProductIdArray();

// Replace the value for data-yotpo-instance-id with your account's widget instance ID.
productTitles.forEach((productTitle, i) => {
productTitle.innerHTML += `
<div
class="yotpo-widget-instance"
data-yotpo-instance-id="791209"
data-yotpo-product-id="${productIdArray[i]}"
data-yotpo-cart-product-id="${productIdArray[i]}"
data-yotpo-section-id="product"
></div>
`
});

// This is needed to render Yotpo widgets after a page has already loaded.
yotpoWidgetsContainer.initWidgets();
}, false);
</script>

2 requirements must be met before this code will successfully add the Review Star On-site Widget to quiz products:

  1. The review star widget must be enabled for your product pages.

  2. The value for data-yotpo-instance-id must be replaced with your account's unique instance ID.

Your account's instance ID can be found in the embed code for your review star widget in Yotpo's dashboard. Click here to jump to instructions on how to find this in Yotpo.

Step-by-step guide

πŸ“• Enable the review star widget on your product pages

First, review stars must be enabled for your product pages. If you've already completed this step, you can skip to the next section.

  1. In your Yotpo Reviews main menu, go to On-Site Widgets.

  2. Click Star Rating.

  3. Customize the widget according to your needs. Learn more about customization options.

  4. Click Save changes.

  5. Click Preview to preview your changes.

  6. When you’re ready to publish, click Publish. You can automatically add the widget to your product pages by clicking Publish now.

πŸ“• Inserting the correct instance ID

Next, we need to get the correct instance ID for the code by pulling up your version of the review star widget embed code.

  1. Inside of the Star Rating Editor, click on the </> icon.

  2. In the pop-up that appears, click Get the code.

  3. Find the section of the code that says data-yotpo-instance-id=

  4. Copy the 6-digit number that follows.

    1. For example, if your widget has the code data-yotpo-instance-id="123456", you would copy 123456.

  5. Replace the 6-digit number inside of the quotation marks in Octane AI's code after data-yotpo-instance-id=.

πŸ“• Adding the code to your website

As a final step, the code has to be added to your website. While you could add the code to theme.liquid, we would recommend adding the code to the specific page that your quiz has been added to.

Since the code example is inside of <script></script> tags, this means it can be added to the same place you added your quiz publish code.

Adding Javascript in the HTML section of page content

  1. In the Shopify admin, go to Sales channels β†’ Online Store β†’ Pages.

  2. Open the page that contains your quiz.

  3. Click on the < > icon to switch the content box to HTML.

  4. Paste the code to insert the Yotpo widget.

Adding Javascript in a custom liquid block in the theme editor

Javascript code can also be added in a custom liquid block. This is a type of block that can be added in the theme editor.

  1. In the theme editor, open the drop-down menu in the middle of the top bar to select your quiz template.

  2. Once your quiz's template has been opened, click on the Custom Liquid block that contains your quiz publish code.

  3. Paste the code to insert the Yotpo widget.

Did this answer your question?