Skip to main content

Social Proofing - API spec

O
Written by Optimize Team

Installation

This snippet should be included in your tags global JS. The snippet provides a convenient way to pass data to our social proof API.

WT.SocialProofing = {
collect: function(data) {
try {
var cfg = WT.optimizeModule.prototype.wtConfigObj;
var domain = cfg.s_domainKey;
var usercookie = WT.helpers.cookie.get("_wt.user-" + domain);

var d = new Date();
var isoString = d.toISOString();
var dateParts = isoString.split(/[T\.]/gi);

try {
usercookie = JSON.parse(WT.optimize.Library.z7f69(usercookie, cfg.s_keyToken)).userSession.split('-')[1];
} catch (err) {
usercookie = '17000000000000000';
}

var payload = {
"domainId": cfg.s_domainKey,
"sessionId": usercookie,
"dateTime": dateParts[0] + ' ' + dateParts[1],
"timeZone": d.getTimezoneOffset()
};

for (var key in data) {
if (data.hasOwnProperty(key)) {
payload[key] = data[key];
}
}

var bodyString = JSON.stringify(payload);

try {
console.log('Payload size in bytes:', new Blob([bodyString]).size);
} catch (e) {
if (document.cookie.match(/_wt.bdebug=true/i)) console.log('Blob not supported for size calculation');
}

if(navigator.sendBeacon) {
var url = 'https://collect.webtrends-optimize.com/social';
var body = new Blob([bodyString], { type: 'text/plain' });
navigator.sendBeacon(url, body);

} else if (window.fetch) {
fetch('https://collect.webtrends-optimize.com/social', {
method: 'POST',
headers: {
'Accept': 'text/plain',
'Content-Type': 'text/plain'
},
body: bodyString
});
}
} catch (err) {
if (document.cookie.match(/_wt.bdebug=true/i)) console.log(err);
}
}
};

Data Capture

Once the WT.SocialProofing snippet is added to your tags global js you will be able to pass the following data to us for processing

Attribute

Type

Description

eventName*

string

required event associated with the pid e.g. views, add_to_cart, purchase

pid*

string

required product id associated with the eventName

dimensions

object

optional object with additional dimensions

The setup for this capture can be done during the onboarding process forming part of your tag setup, or at a later date.

Please note that when passing the events we recommend adding a TTL suffix which indicates how long an event is valid for, and helps pull the relevant data for a specific time period.

Suffix

TTL

_<n>h

TTL in hours

e.g. views_1h

_<n>d

TTL in days max 7 days

e.g. purchase_1d


Example data capture call:

WT.SocialProofing.collect({
eventName: 'views_1h', //the event that occured
pid: '123456', //product id
dimensions: {
country: 'GB',
... //any other dimensions you want to add
}
});

Read API

Once the WT.SocialProofing snippet is installed and the data capture is setup, contact us and we will then setup and provide you with a personalised read API and Client specific documentation.

The read api will by default return unique user session aggregates of pid events passed in the data capture.

Please note that dimension attributes are usually returned as the last passed value against the product id, if you require specific dimension(s) to be used to filter aggregate data please get in touch as this will require additional setup.

Example URI: companyname-sp-read.webtrends-optimize.workers.dev

Method: GET

Example Endpoints:

/health-check

Quickly check the health of your social proof resource

Example Response:

{
"status": "ok",
"lastUpdated": "2026-06-15T12:25:25.321Z", //the last time the data was updated
"count": 500 //the number of pid records
}

/allraw

Quickly get the current raw data stored for your social proof resource

Example Response:

{
"index_index": {
"views_1d": 0,
"purchase_1d": 1
},
"index": [
"views_1d",
"purchase_1d"
],
"values": {
"123456": [
456,
5
]
...
},
"dimensions_lookup": {
"123456": {
"country": "GB"
...
}
...
}
}

Queries

Parameter

Type

Description

pid

string

single or comma sperated list of product ids

e.g. 645694,643456

Single pid Example Request:

let  req = await fetch('https://companyname-sp-read.webtrends-optimize.workers.dev/?pid=123456');
let res = await req.json();

Single pid Example Response:

{
"123456": {
"views_1d": "74",
"purchase_1d": "4",
"dimensions": {
"country": "GB"
}
}
}

Multiple pid Example Request:

let  req = await fetch('https://companyname-sp-read.webtrends-optimize.workers.dev/?pid=123456,654321');
let res = await req.json();

Multiple pid Example Response:

{
"123456": {
"views_1d": "74",
"purchase_1d": "4",
"dimensions": {
"country": "GB"
}
},
"654321": {
"views_1d": "90",
"purchase_1d": "6",
"dimensions": {
"country": "GB"
}
}
}
Did this answer your question?