REST API

Visitor Activities API Endpoint

Use Visitor Activities API Endpoint to work with PersonalizeWP programmatically.

The Visitor Activities endpoint allows developers to retrieve all recorded activities for a specific visitor. This data can be used to create personalized experiences based on the visitor's past interactions with your site.

Endpoint Details

  • URL: /wp-json/personalizewp/v1/visitor-activities
  • Method: POST
  • Content Type: application/json

Request Parameters

The request body should be a JSON object containing the following parameters:

Parameter

Type

Required

Description

uid

string

Yes

The visitor's unique identifier

filters

array

No

Array of filters to apply to the activities

Filters

The filters parameter allows you to filter the returned activities by specific criteria. The filter is structured as an array of key/value pairs where each key is one of the following:

  • id – Filter by activity ID
  • activity_type – Filter by activity type
  • url – Filter by the URL where the activity occurred
  • object_id – Filter by object ID
  • object_type – Filter by object type

When multiple filters are provided, they are combined using an AND condition, meaning all conditions must be met for an activity to be included in the results.

Response

The endpoint returns an array of activity records associated with the visitor. Each activity record contains the following fields:

Field

Type

Description

id

number

The activity's unique identifier

activity_type

string

The activity's type

url

string

The recorded object's URL

object_id

number

The recorded object's unique identifier

object_type

string

The recorded object's type

lead_score

number

The recorded object's lead score

created

date (UTC)

When the activity was created

Example Usage

Basic Request

This example shows how to fetch all activities for the current visitor:

( async () => { const PWP = localStorage.getItem('pwptrackeduser') || ''; const UID = (PWP) ? JSON.parse(PWP).id : null;

if (UID) { const baseURL = '/wp-json/'; // This is available on frontend as "window.pwpSettings.root" const namespace = 'personalizewp/v1/'; const endpoint = 'visitor-activities';

const response = await fetch( ${baseURL}${namespace}${endpoint}, { method: "POST", cache: "no-cache", headers: { "Accept": "application/json, /;q=0.1", "Cache-Control": "no-cache, private", "Content-type": "application/json", "X-Requested-With": "XMLHttpRequest", }, body: JSON.stringify({ uid: UID }), });

if (response.ok){ const activities = await response.json(); console.log(activities); } } })();

Request with Filters

This example shows how to fetch only activities of a specific type and object type:

( async () => { const PWP = localStorage.getItem('pwptrackeduser') || ''; const UID = (PWP) ? JSON.parse(PWP).id : null;

if (UID) { const baseURL = '/wp-json/'; // Available as "window.pwpSettings.root" const namespace = 'personalizewp/v1/'; const endpoint = 'visitor-activities';

// Filter for only viewed products const filters = [ { activitytype: 'view' }, { objecttype: 'product' } ];

const response = await fetch( ${baseURL}${namespace}${endpoint}, { method: "POST", cache: "no-cache", headers: { "Accept": "application/json, /;q=0.1", "Cache-Control": "no-cache, private", "Content-type": "application/json", "X-Requested-With": "XMLHttpRequest", }, body: JSON.stringify({ uid: UID, filters: filters }), });

if (response.ok){ const viewedProducts = await response.json(); console.log(viewedProducts); } } })();

Common Use Cases

The Visitor Activities endpoint is particularly useful for:

  1. Creating "Recently Viewed" product displays
  2. Building personalized product recommendations
  3. Tracking user engagement with specific content
  4. Creating conditional content based on past visitor behavior
  5. Analyzing user journey through your website

For a practical implementation example, see our guide on Creating a "Previously Viewed" Block.

Notes

  • The endpoint currently does not support pagination, so all matching activities will be returned in a single response.
  • Activities are returned in chronological order, with the most recent activities first.
  • Consider implementing caching for frequent requests to improve performance.