This guide will walk you through the process of integrating the PowerReviews platform into your Shopify store. By following these steps, you can add Reviews and other powerful social proof features to your site. We also offer a Professional Services integration where we integrate the JavaScript code to your Shopify store for you. To learn more about Shopify Professional Services, click here.
Before You Begin
Before you start, please have the following credentials from your PowerReviews Welcome Email on hand:
- API Key
- Locale
- Merchant Group ID
- Merchant ID
Product Data
For the PowerReviews code to work effectively, you need to ensure that the appropriate and correct product information is provided. As you add products via the Products navigation menu, ensure you add the following required fields at minimum:
- Key - this Shopify field is required and should state PR Field
- Title - the name of your product
- Description - a brief description of your product
- Product Type - the category of your product (for example: Shoes)
- Image - the publicly-hosted URL of the product image
- Vendor - the brand of the product
- Variants - any variants of your product (if you aren't using product variants, ignore this field)
Additionally, you must include the following fields if you participate in PowerReviews Syndication:
- Barcode - the UPC of the product
- SKU - the manufacturer ID of the product
- Variant Barcodes - the UPCs of the variant of the product
Step 1: Create the Core PowerReviews Snippet
This central snippet will contain all the necessary JavaScript and logic to power the PowerReviews components on your store.
- From your Shopify Admin, go to Online Store > Themes.
- On your current theme, click Actions > Edit code.
- In the file explorer on the left, open the Snippets directory.
- Right-click the Snippets directory and add a New File. Name it
powerreviews.liquid. - Copy the code below and paste it into your new
powerreviews.liquidfile. -
Important: Replace the placeholder values for
api_key,locale,merchant_group_id, andmerchant_idwith your actual PowerReviews credentials. - Click Save.
{% comment %}
PowerReviews Core JavaScript Snippet
This file contains all the necessary logic for displaying PowerReviews components.
{% endcomment %}
<script src="https://ui.powerreviews.com/stable/4.1/ui.js" async></script>
<script>
window.pwr = window.pwr || function () {
(pwr.q = pwr.q || []).push(arguments);
};
const pwrCredentials = {
api_key: '<API_KEY>',
locale: '<LOCALE>',
merchant_group_id: '<MERCHANT_GROUP_ID>',
merchant_id: '<MERCHANT_ID>'
};
function prRandomNumber() {
return Math.round((Math.random() * 100000000));
}
function loadPowerReviews() {
let pwrElements = [];
/* PDP (Product Detail Page) Components */
if (document.getElementById('pr-reviewdisplay') && !document.getElementById('pr-reviewdisplay').dataset.prMounted) {
pwrElements.push({
...pwrCredentials,
page_id: '{{ product.id }}',
review_wrapper_url: '{{ shop.url }}/pages/write-a-review?pr_page_id={{ product.id }}',
product: {
name: "{{ product.title | replace: '+', ' ' | json }}",
url: "{{ shop.url }}{{ product.url }}",
image_url: "https:{{ product.featured_image | product_img_url: 'large' }}",
description: "{{ product.description | strip_html | strip_newlines | escape }}",
category_name: {% if product.type != '' %}"{{ product.type | json }}"{% else %} "Default" {% endif %},
upc: "{{ product.barcode | remove: ' ' | remove: '-' }}",
brand_name: "{{ product.vendor | json }}",
price: "{{ product.price | money_without_currency }}",
in_stock: "{{ product.available }}",
variants: [
{%- for variant in product.variants -%}
{
page_id_variant: "{{variant.id}}",
upc: "{{ variant.barcode | remove: ' ' | remove: '-' }}"
}{%- unless forloop.last -%}, {%- endunless -%}
{%- endfor -%}
]
},
components: {
ReviewSnippet: "pr-reviewsnippet",
ReviewDisplay: "pr-reviewdisplay"
}
});
}
/* PLP (Category & Search Page) Snippets */
document.querySelectorAll('[data-pr-component="CategorySnippet"]').forEach(el = {
if (!el.dataset.prMounted) {
el.id = 'snippet-' + prRandomNumber();
pwrElements.push({
...pwrCredentials,
page_id: el.dataset.prPageId,
components: {
CategorySnippet: el.id
}
});
}
});
/* Write-a-Review Form */
if (document.getElementById('pr-write') && !document.getElementById('pr-write').dataset.prMounted) {
pwrElements.push({
...pwrCredentials,
on_submit: function(config, data) {
window.scrollTo(0, 0);
},
components: {
Write: 'pr-write'
}
});
}
/* Render all components */
if (pwrElements.length 0) {
pwr("render", pwrElements);
}
}
// Initial load
document.addEventListener('DOMContentLoaded', function() {
loadPowerReviews();
});
</script>
Step 2: Add PowerReviews to Your Theme
Now, you'll include the snippet you just created in your main theme file so it loads on every page.
- In the Layout directory of your theme code, open the theme.liquid file.
- Scroll to the very bottom of the file.
-
Just before the closing </body> tag, paste the following line:
{%- render 'powerreviews' -%} - Click Save.
Step 3: Implement Product Detail Page (PDP) Components
You will now create the section and snippet needed to display reviews on your product pages.
A. Create the Review Display Section
This section will house the main review content, including the review list, histogram, and sorting/filtering options.
- Under the Sections directory, right click the directory name and add a New File.
- Name it powerreviews-pdp-review-display.liquid.
- Paste the following code into the file and Save.
<!-- PowerReviews Code Start -->
<div id="pr-reviewdisplay"></div>
<!-- PowerReviews Code End -->
{% schema %}
{
"name": "PowerReviews: Reviews",
"tag": "section",
"settings": []
}
{% endschema %}
B. Create the PDP Review Snippet
This snippet displays the star rating and review count, typically near the product title.
- Under the Snippets directory, right click the directory name and add a New File.
- Name it powerreviews-pdp-snippet.liquid.
- Paste the following code into the file and Save.
<!-- PowerReviews Code Start -->
<div id="pr-reviewsnippet"></div>
<!-- PowerReviews Code End -->
C. Place the PDP Components in Your Theme
-
For Shopify OS 2.0 Themes (Most common):
- Open Templates/main-product.json
- Find bottom of "sections" and add:
"powerreviews-pdp-review-display": {
"type": "powerreviews-pdp-review-display",
"settings": {
}
},
"powerreviews-pdp-question-display": {
"type": "powerreviews-pdp-question-display",
"settings": {
}
}
- Add "powerreviews-pdp-review-display" and "powerreviews-pdp-question-display" at bottom of "order" section*
- Navigate to Sections and open main-product.liquid.
- Find the product title, which often looks like <h1 class="product__title">.
- Directly below the line with the product title, add the following code to render the star snippet:
{%- render 'powerreviews-pdp-snippet' -%}
- Go to your Shopify Admin > Online Store > Themes and click Customize.
- Navigate to a product page. On the left panel, click Add section and add your PowerReviews: Reviews section. Drag it to your desired location on the page.
-
For Older (OS 1.0) Themes:
- Navigate to Templates and open product.liquid.
- Find the product title (e.g., <h1>{{ product.title }}</h1>) and paste directly below it.
{%- section 'powerreviews-pdp-review-display' -%}- At the bottom of the file, add the following line to render the display section:
{%- section 'powerreviews-pdp-review-display' -%}- Click Save.
Step 4: Implement Product Listing Page (PLP) Snippets
This will add star ratings to your products on collection and search results pages.
- Under the Snippets directory, right click the directory name and add a New File.
- Name it powerreviews-plp-snippet.liquid.
- Paste the following code into the file and Save.
<!-- PowerReviews Code Start -->
<div data-pr-component="CategorySnippet" data-pr-page-id="{{ product.id }}"></div>
<!-- PowerReviews Code End -->- Now, you need to find your product grid/card snippet/product card. This file's name varies by theme but is often called product-card.liquid, product-grid-item.liquid, or similar.
- Open this file and locate where the product title or price is displayed. Paste the following line in a suitable location (e.g., below the title):
{%- render 'powerreviews-plp-snippet', product: product -%}Note: Depending on the file, you may need to adjust product: product to match the variable used for the product in that context (e.g., product: item or product: card_product).
- Click Save.
Step 5: Create the Write-a-Review Page
This page will host the form your customers use to submit reviews.
- From your Shopify Admin, go to Online Store > Pages.
- Click Add page.
- For the Title, enter Write-a-Review.
- In the content editor, click the Show HTML (<>) button.
- Paste the following code into the editor:
<!-- PowerReviews Code Start -->
<div id="pr-write"></div>
<!-- PowerReviews Code End -->- Click Save.
Step 6: Install the Checkout Beacon
The Checkout Beacon is essential for collecting order data, which powers your Follow-Up Email campaigns to solicit reviews from customers post-purchase.
- From your Shopify Admin, go to Settings > Customer events.
- Click Add custom pixel. Name it PowerReviews Checkout Beacon and click Add pixel.
- Paste the following code into the Code box.
- Important: Remember to replace the placeholder values for <MERCHANT_GROUP_ID>, <MERCHANT_ID>, and <LOCALE> with your credentials.
- Click Save, and then click Connect.
analytics.subscribe('checkout_completed', (event) => {
const pwrScript = document.createElement('script');
pwrScript.src = 'https://static.powerreviews.com/t/v1/tracker.js';
document.body.appendChild(pwrScript);
let count = 0;
const prCheck = function () {
count += 1;
if (typeof POWERREVIEWS != 'undefined') {
clearInterval(prIntervalSet);
const prBeacon = POWERREVIEWS.tracker.createTracker({ merchantGroupId: '<MERCHANT_GROUP_ID>'});
const checkout = event.data.checkout;
const lineItems = checkout.lineItems;
const products = [];
lineItems.forEach(item = {
if (item.variant.price.amount 0) {
products.push({
page_id: item.variant.product.id,
product_name: item.title,
quantity: item.quantity,
unit_price: item.variant.price.amount,
page_id_variant: item.variant.id
});
}
});
const orderFeed = {
merchantGroupId: '<MERCHANT_GROUP_ID>',
merchantId: '<MERCHANT_ID>',
locale: '<LOCALE>',
merchantUserId: checkout.order.customer.id,
marketingOptIn: true,
userEmail: checkout.email,
userFirstName: checkout.billingAddress.firstName,
userLastName: checkout.billingAddress.lastName,
orderId: checkout.order.id,
orderItems: products
};
prBeacon.trackCheckout(orderFeed);
} else if (count 10) {
clearInterval(prIntervalSet);
}
}
let prIntervalSet = setInterval(prCheck, 50);
});Your PowerReviews implementation is now complete! Please review your product pages, collection pages, and test the checkout process to ensure everything is displaying and functioning correctly.
Optional Steps: Additional Functionality
We do support some additional functionality through the use of Callback functions, two of which are included below but more can be found in our JavaScript Reference Guide.
Scroll to reviews in tab
This will scroll a user down to the review display and open the tab that the display is nested into.
on_read_reviews_click: function() {
if (document.getElementById("//---- <tab id> ----//")) {
document.getElementById("//---- <tab id> ----//").click();
(document.getElementById("//---- <tab id> ----//").scrollIntoView({
block: "start",
behavior: "smooth"
});
}
},
Make stars clickable
This will make the stars clickable and scroll the user down to the review display.
on_render: function (data,config) {
if(config.component === 'ReviewSnippet') {
let reviewSnippet = document.querySelector('.pr-snippet-review-count'),
scrollToReviews = function() {
document.getElementById('pr-reviewdisplay').scrollIntoView({block: 'start', behavior: 'smooth'})
};
reviewSnippet.addEventListener('click', scrollToReviews);
}
},