Skip to main content

Review created

This event is triggered when a review is successfully created. It provides details about the created review.

Event details​

When the reviewCreated event is triggered, the received event.detail object includes the following properties:

Usage example​

Before listening for the reviewCreated event, ensure the SDK and the Reviews module are ready:

function subscribeToReviewCreated() {
const reviewCreatedEventType = window.gw.sdk.reviews.events.REVIEW_CREATED;

window.gw.sdk.on(reviewCreatedEventType, (event) => {
console.log(event.detail);
});
}

function onSdkReady() {
const moduleName = window.gw.sdk.common.constants.modules.REVIEWS;

window.gw.sdk.runIfModuleReady(moduleName, () => {
subscribeToReviewCreated();
});
}

if (window.gw && window.gw.sdk) {
onSdkReady();
} else {
document.addEventListener("gwSdkReady", onSdkReady);
}

// Example output:
// {type: 'reviewCreated', review: {id: 123, rating: 5, title: 'Great product', body: '...', product: {id: 456, ...}, isPublished: true, ...}}

This code ensures the SDK and the Reviews module are ready before setting up the event listener, allowing you to respond when a review is created and access the relevant details.

Types​

ReviewItemSdkDto​

ReviewItemSdkDto
interface
Properties
bodystring
Review text
createdAtstring
Date the review was created
customerReviewItemCustomerSdkDto | null
Review author, or null if not available
idnumber
Review ID
imagesReviewItemImageSdkDto[]
Images attached to the review
isCustomerAuthorboolean
Whether the current customer is the author of the review
isCustomerVotedboolean
Whether the current customer has voted for the review
isIncentivizedboolean
Whether the author received a reward for the review
isPinnedboolean
Whether the review is pinned by the merchant
isPublishedboolean
Whether the review is published and visible in the storefront
productReviewItemProductSdkDto | null
Reviewed product, or null for a shop review
ratingnumber
Rating from 1 to 5
replyReviewItemReplySdkDto | null
Merchant reply, or null if there is none
shopNamestring
Name of the shop
titlestring | null
Review title, or null if not provided
uidstring
Unique identifier for state management
votesnumber
Number of helpful votes