Analytics
Record page views and custom events so the site owner sees them in the dashboard.
Quick start
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
const forms = window.Portal.analytics.forms;initPageLoad()
Records a page view for route (default: the current path). Call once per page load.
const analyticsEventResponse = await window.Portal.analytics.initPageLoad(route);Parameters
| Name | Type | Required | Description |
|---|---|---|---|
route | string | No | Records 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
const subscribers = window.Portal.analytics.subscribers;track()
Records one event.
const analyticsEventResponse = await window.Portal.analytics.track(payload);Parameters
| Name | Type | Required | Description |
|---|---|---|---|
payload | PortalAnalyticsEventPayload | Yes | One 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().
const analyticsEventResponse = await window.Portal.analytics.trackEvent(payload);Parameters
| Name | Type | Required | Description |
|---|---|---|---|
payload | PortalAnalyticsEventPayload | Yes | One 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.
const analyticsEventResponse = await window.Portal.analytics.trackModuleEvent(module, event, resource_name, resource_reference, route, metadata);Parameters
| Name | Type | Required | Description |
|---|---|---|---|
module | string | Yes | The module key. |
event | string | Yes | The event to listen for. |
resource_name | string | No | — |
resource_reference | string | No | — |
route | string | No | The page route, for example /pricing. |
metadata | Record<string, unknown> | No | Free-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.
const analyticsEventResponse = await window.Portal.analytics.forms.completed(formName, formReference, route, metadata);Parameters
| Name | Type | Required | Description |
|---|---|---|---|
formName | string | Yes | The form's display name. |
formReference | string | No | The form's reference. |
route | string | No | The page route, for example /pricing. |
metadata | Record<string, unknown> | No | Free-form extra data. |
Returns
Resolves with a PortalAnalyticsEventResponse: An analytics event as stored by the server.
loaded()
A form finished rendering.
const analyticsEventResponse = await window.Portal.analytics.forms.loaded(formName, formReference, route, metadata);Parameters
| Name | Type | Required | Description |
|---|---|---|---|
formName | string | Yes | The form's display name. |
formReference | string | No | The form's reference. |
route | string | No | The page route, for example /pricing. |
metadata | Record<string, unknown> | No | Free-form extra data. |
Returns
Resolves with a PortalAnalyticsEventResponse: An analytics event as stored by the server.
pageLoad()
A page containing a form was opened.
const analyticsEventResponse = await window.Portal.analytics.forms.pageLoad(formName, formReference, route, metadata);Parameters
| Name | Type | Required | Description |
|---|---|---|---|
formName | string | No | The form's display name. |
formReference | string | No | The form's reference. |
route | string | No | The page route, for example /pricing. |
metadata | Record<string, unknown> | No | Free-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.
const analyticsEventResponse = await window.Portal.analytics.subscribers.pageLoad(route, metadata);Parameters
| Name | Type | Required | Description |
|---|---|---|---|
route | string | No | The page route, for example /pricing. |
metadata | Record<string, unknown> | No | Free-form extra data. |
Returns
Resolves with a PortalAnalyticsEventResponse: An analytics event as stored by the server.
signup()
Somebody signed up to a list.
const analyticsEventResponse = await window.Portal.analytics.subscribers.signup(listName, listReference, route, metadata);Parameters
| Name | Type | Required | Description |
|---|---|---|---|
listName | string | No | — |
listReference | string | No | — |
route | string | No | The page route, for example /pricing. |
metadata | Record<string, unknown> | No | Free-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().
| Name | Type | Required | Description |
|---|---|---|---|
module | string | Yes | The module the event belongs to, for example 'forms'. |
event | string | Yes | The event name, for example 'completed'. |
resource_name | string | No | Display name of the thing involved (a form name, a list name). |
resource_reference | string | No | Reference of the thing involved. |
route | string | No | The page route the event happened on. |
metadata | Record<string, unknown> | No | Free-form extra data. |
PortalAnalyticsEventResponse
An analytics event as stored by the server.
| Name | Type | Required | Description |
|---|---|---|---|
id | number | Yes | Event id. |
module | string | Yes | The module the event belongs to. |
event | string | Yes | The event name. |
resource_name | string | No | Display name of the thing involved. |
resource_reference | string | No | Reference of the thing involved. |
route | string | No | The page route. |
metadata | Record<string, unknown> | No | Free-form extra data. |
created_at | string | Yes | ISO timestamp it was recorded. |
updated_at | string | Yes | ISO timestamp of the last change. |