Skip to content

Analytics ​

Record page views and custom events so the site owner sees them in the dashboard.

Quick start ​

ts
await window.Portal.analytics.initPageLoad();
await window.Portal.analytics.forms.completed('Contact form', 'FORM_REF');
await window.Portal.analytics.trackModuleEvent('ecommerce', 'coupon_used', 'SPRING', undefined, window.location.pathname);

API reference ​

window.Portal.analytics ​

Portal.analytics — record what visitors do on the site so the owner sees it in the dashboard.

forms ​

Shortcuts for form events.

Type: PortalAnalyticsFormsHelpers

ts
const forms = window.Portal.analytics.forms;

initPageLoad() ​

Records a page view for route (default: the current path). Call once per page load.

ts
const analyticsEventResponse = await window.Portal.analytics.initPageLoad(route);

Parameters

NameTypeRequiredDescription
routestringNoRecords a page view for route (default: the current path).

Returns

Resolves with a PortalAnalyticsEventResponse: An analytics event as stored by the server.

subscribers ​

Shortcuts for subscriber-list events.

Type: PortalAnalyticsSubscribersHelpers

ts
const subscribers = window.Portal.analytics.subscribers;

track() ​

Records one event.

ts
const analyticsEventResponse = await window.Portal.analytics.track(payload);

Parameters

NameTypeRequiredDescription
payloadPortalAnalyticsEventPayloadYesOne analytics event to record with Portal.analytics.track().

Returns

Resolves with a PortalAnalyticsEventResponse: An analytics event as stored by the server.

trackEvent() ​

Same as track().

ts
const analyticsEventResponse = await window.Portal.analytics.trackEvent(payload);

Parameters

NameTypeRequiredDescription
payloadPortalAnalyticsEventPayloadYesOne analytics event to record with Portal.analytics.track().

Returns

Resolves with a PortalAnalyticsEventResponse: An analytics event as stored by the server.

trackModuleEvent() ​

Records an event with positional arguments instead of an object.

ts
const analyticsEventResponse = await window.Portal.analytics.trackModuleEvent(module, event, resource_name, resource_reference, route, metadata);

Parameters

NameTypeRequiredDescription
modulestringYesThe module key.
eventstringYesThe event to listen for.
resource_namestringNo—
resource_referencestringNo—
routestringNoThe page route, for example /pricing.
metadataRecord<string, unknown>NoFree-form extra data.

Returns

Resolves with a PortalAnalyticsEventResponse: An analytics event as stored by the server.

window.Portal.analytics.forms ​

Shortcuts for recording form events (Portal.analytics.forms).

completed() ​

A form was submitted successfully.

ts
const analyticsEventResponse = await window.Portal.analytics.forms.completed(formName, formReference, route, metadata);

Parameters

NameTypeRequiredDescription
formNamestringYesThe form's display name.
formReferencestringNoThe form's reference.
routestringNoThe page route, for example /pricing.
metadataRecord<string, unknown>NoFree-form extra data.

Returns

Resolves with a PortalAnalyticsEventResponse: An analytics event as stored by the server.

loaded() ​

A form finished rendering.

ts
const analyticsEventResponse = await window.Portal.analytics.forms.loaded(formName, formReference, route, metadata);

Parameters

NameTypeRequiredDescription
formNamestringYesThe form's display name.
formReferencestringNoThe form's reference.
routestringNoThe page route, for example /pricing.
metadataRecord<string, unknown>NoFree-form extra data.

Returns

Resolves with a PortalAnalyticsEventResponse: An analytics event as stored by the server.

pageLoad() ​

A page containing a form was opened.

ts
const analyticsEventResponse = await window.Portal.analytics.forms.pageLoad(formName, formReference, route, metadata);

Parameters

NameTypeRequiredDescription
formNamestringNoThe form's display name.
formReferencestringNoThe form's reference.
routestringNoThe page route, for example /pricing.
metadataRecord<string, unknown>NoFree-form extra data.

Returns

Resolves with a PortalAnalyticsEventResponse: An analytics event as stored by the server.

window.Portal.analytics.subscribers ​

Shortcuts for recording subscriber-list events (Portal.analytics.subscribers).

pageLoad() ​

A page with a sign-up box was opened.

ts
const analyticsEventResponse = await window.Portal.analytics.subscribers.pageLoad(route, metadata);

Parameters

NameTypeRequiredDescription
routestringNoThe page route, for example /pricing.
metadataRecord<string, unknown>NoFree-form extra data.

Returns

Resolves with a PortalAnalyticsEventResponse: An analytics event as stored by the server.

signup() ​

Somebody signed up to a list.

ts
const analyticsEventResponse = await window.Portal.analytics.subscribers.signup(listName, listReference, route, metadata);

Parameters

NameTypeRequiredDescription
listNamestringNo—
listReferencestringNo—
routestringNoThe page route, for example /pricing.
metadataRecord<string, unknown>NoFree-form extra data.

Returns

Resolves with a PortalAnalyticsEventResponse: An analytics event as stored by the server.

Types ​

PortalAnalyticsEventPayload ​

One analytics event to record with Portal.analytics.track().

NameTypeRequiredDescription
modulestringYesThe module the event belongs to, for example 'forms'.
eventstringYesThe event name, for example 'completed'.
resource_namestringNoDisplay name of the thing involved (a form name, a list name).
resource_referencestringNoReference of the thing involved.
routestringNoThe page route the event happened on.
metadataRecord<string, unknown>NoFree-form extra data.

PortalAnalyticsEventResponse ​

An analytics event as stored by the server.

NameTypeRequiredDescription
idnumberYesEvent id.
modulestringYesThe module the event belongs to.
eventstringYesThe event name.
resource_namestringNoDisplay name of the thing involved.
resource_referencestringNoReference of the thing involved.
routestringNoThe page route.
metadataRecord<string, unknown>NoFree-form extra data.
created_atstringYesISO timestamp it was recorded.
updated_atstringYesISO timestamp of the last change.