This guide describes how to make further modifications to the Main Widget using Javascript. This may require a listening event to ensure JS is properly run after the Widget has loaded.
In This Guide
Listening for Events
Events are dispatched on document. Attach listeners to document:
function addEventListenerStamped(el, eventName, handler) {
if (el.addEventListener) { el.addEventListener(eventName, handler); }
else { el.attachEvent('on' + eventName, function () { handler.call(el); }); }
}
// Example: listen for the reviews widget loaded event
addEventListenerStamped(document, 'stamped:reviews:loaded', function(e) {
console.log(e);
});
You can also use the built-in helper:
StampedFn.on('stamped:reviews:loaded', function(e) {
console.log(e);
});
Events
Reviews & Questions
| Event Name | Fired When |
|---|---|
| stamped:reviews:loaded | Reviews main widget has loaded |
| stamped:reviews:submitted | A review is submitted through the widget form |
| stamped:reviews:submitError | A review submission fails |
| stamped:reviews:widget:loaded | A display/review widget has finished rendering |
| stamped:questions:loaded | The Q&A section has loaded in the main widget |
| stamped:widget:reloading | Display widgets are reloading |
| stamped:badges:loaded | Star-rating badges have loaded |
| stamped:macy:loaded | The masonry (Macy) layout has loaded |
Photos / UGC submission
| Event Name | Fired When |
|---|---|
| stamped:photo:selected | A photo/video is selected on the submission form |
| stamped:photo:maxed | The maximum number of photos/videos (5) is reached |
| stamped:photo:sizeError | A selected video exceeds the size limit |
| stamped:photo:invalid | A selected file is not a valid image/video |
UGC / Photo Modal (Lightbox)
| Event Name | Fired When |
|---|---|
| stamped:ugcmodal:open | The UGC photo modal is opened |
| stamped:ugcmodal:paged | The user navigates between photos in the modal |
| stamped:ugcmodal:last | The user reaches the last photo in the modal |
Initialisation
| Event Name | Fired When |
|---|---|
| stamped:init:starting | The widget library is starting up |
| stamped:init:getAppKey | The app key has been retrieved during init |
| stamped:script-shopify-checkout:loaded | The Shopify checkout script has loaded |
Loyalty Launcher Events - ownership decision needed
The bundle dispatches these events, but they belong to the rewards/loyalty launcher.
| Event Name | Fired When |
|---|---|
| stamped:launcher:loaded | The rewards launcher has loaded |
| stamped:launcher:opened | The rewards launcher is opened |
| stamped:launcher:closed | The rewards launcher is closed |
| stamped:rewards:init | The rewards data has initialised |
| stamped:rewards:earned | A customer earns points via an activity |
| stamped:rewards:redeemed | A customer redeems points |
| stamped:rewards:coupon:applied | A rewards coupon is applied |
JS Methods
Methods are split into two groups: developer-facing methods that are safe to call directly (with examples), and UI-triggered handlers that the widget calls via its own rendered markup and generally should not be called by hand.
Group 1 - Developer-facing methods (safe to call directly)
| Method | What it does | Example |
|---|---|---|
| StampedFn.loadWidget() | Loads/reloads the main widget | StampedFn.loadWidget(); |
| StampedFn.reloadUGC() | Reloads all widgets on the page (e.g. after changing data-product-id) | StampedFn.reloadUGC(); |
| StampedFn.loadDisplayWidgets() | Loads all display widgets on the page | StampedFn.loadDisplayWidgets(); |
| StampedFn.loadBadges() | Reloads the star-rating badge widgets (class .stamped-product-reviews-badge) | StampedFn.loadBadges(); |
| StampedFn.pageReviews(page) | Loads a specific page of reviews. page = page number | StampedFn.pageReviews(2); |
| StampedFn.toggleForm(type) | Shows/hides a form. type = 'review' or 'question' | StampedFn.toggleForm('review'); |
| StampedFn.submitQuestionForm() | Submits the question form (defaults to #new-question-form when no argument is passed) | StampedFn.submitQuestionForm(); |
| StampedFn.getLoggedInCustomer() | Returns the currently logged-in customer object | const c = StampedFn.getLoggedInCustomer(); |
| StampedFn.getOptions() | Returns the widget's current options object | const o = StampedFn.getOptions(); |
| StampedFn.setOptions(options) | Merges values into the widget options. options = object | StampedFn.setOptions({ is_disable_cache: true }); |
| StampedFn.on(eventName, handler) | Adds a listener for a Stamped event. eventName = string, handler = function | StampedFn.on('stamped:reviews:loaded', function(e){ console.log(e); }); |
| StampedFn.triggerEvent(eventName, detail) | Dispatches a Stamped event. detail = optional object | StampedFn.triggerEvent('stamped:reviews:loaded'); |
Group 2 - UI-triggered handlers (called by the widget, not usually by hand)
These methods are wired to the widget's own rendered controls (via inline onclick) and generally should not be called directly. Where an argument is shown, it is the DOM element that triggered the action.
| Method | Notes |
|---|---|
| setRating(el) | el = the clicked star element (reads data-value) |
| submitForm(el) | el = an element inside the review form |
| sortReviews(el) | el = the sort <select> (reads el.value) |
| sortQuestions(el) | el = the sort <select> (reads el.value) |
| filterReviews(el) | el = a filter <select> |
| filterClear(type) | type = 'qna' clears Q&A filters; anything else clears review filters |
| pageQuestions(el) | ⚠️ Gotcha: reads data-page from the passed element — it does not take a page number. pageQuestions(2) will not work. |
| voteReview(el, reviewId, vote) | el = vote button, reviewId = number, vote = 1 or -1 |
| openUGCModal(...) | Internal — opens the UGC photo modal; complex multi-argument signature |
| openUGCPhoto(...) | Internal — opens a specific photo review in the lightbox |