Client-side APIs
This article presents a set of functions and methods that enable you to extend the personalization capabilities of the user experience on your website.
Recommendations
The result is returned as a set of products in JSON format.
Syntax
GF.Recommendations.get(id, opts, callback)Parameters:
id: The identifier of the recommendations strategy.
opts: Optional parameters
context: The page context, taken directly from the page unless you explicitly specify another one.
maxProducts: Overrides the number of products from the Strategy configuration window.
callback: A callback function that is executed once data on recommendations is returned.
Usage example:
GF.Recommendations.get('6364138cfe9b4f979a044a32', {
maxProducts: 10
}, function(err, data) {
if (err) {
console.log(err);return;
}
const template = '<a href="{url}" class="demo-recs__item" style="flex:1;margin:0 5px;border: 1px solid #ccc;padding:10px;background: #fff;"><img src="{image_url}" style="display:block;max-width:100px;height:auto;max-height:100px;margin:0 auto;"/><div>{name}</div><div>{price}</div></a>';
let html = '<div class="demo-recs" style="display:flex;">';
for(let i = 0; i < data.slots.length; i++) {
html += template.replace(/{([^{}]+)}/g, function(keyExpr, key) {
return data.slots[i].item[key] || "";
});
}
html += '</div>';
document.body.insertAdjacentHTML('afterbegin', html);
})Wait for a CSS Element
This method waits for the loading of an element on the page and then executes a function.
Syntax
Parameters:
selector: A valid CSS selector that specifies which element to look for in the DOM.
callback: The function to execute.
minElements (optional, default: 1): The minimum number of selected resources that must be rendered before executing the function.
interval (optional, default: 100): How often the page should recheck for the element (in milliseconds).
maximumRetries (optional, default: infinite): The maximum number of page recheck attempts to find the elements.
Returns: Nothing
Activation Example:
Wait for an event
This method waits for a specific event to occur on the page and then executes a function.
Syntax:
The function is triggered when the event or page view is registered by the browser.
Available conditions:
sl-event: Trigger for event occurrence.
spa: Trigger for SPA event occurrence.
Usage example and response:
Overlay
Syntax:
Parameters:
Layout (htmlCode, cssCode, jsCode): Basic parameters for the overlay.
Optional parameters
destroyOnClose: Removes the overlay from the DOM when closed. Default is true.
closeIcon: Customized overlay close icon (string value, e.g., inline SVG).
closeEventName: Trigger an event when the overlay is closed.
Usage example:
Social Proof and Product Data
Parameters:
SKU Array
Options
interest: Boolean value, returns the type of interest in the product (purchase, view).
timeframes (daily, twoDays, weekly, twoWeeks, monthly) - an array of string values, returns the number of interest events relative to the product (purchases, views).
data: Boolean value, specifies whether to return product properties from the feed.
Usage example:
Last updated
Was this helpful?