Overview
The Track Goal API records a goal conversion for the specified visitor. Every goal tracked through this API is recorded at the project level. In addition, if the tracked goal is associated with one or more active FullStack A/B Test experiments for which the visitor has qualified, the SDK automatically attributes the goal conversion to each applicable experiment. No additional API calls are required for experiment-level goal tracking.
When to Use
Call the Track Goal API whenever the visitor completes a measurable business event, such as:
Purchase
Registration
Form submission
Subscription
Download
Login
Checkout completion
Method Signature
track_goal(
goal_name: str,
user_context: PageSenseUserContext,
)
Parameters
Parameter | Type | Required | Description |
goal_name | str | Yes | Name of the configured goal. |
user_context | PageSenseUserContext | Yes | Visitor information used for goal attribution. |
Return Value
Type | Description |
None | This API does not return a value. |
Usage Example
from pagesense import PageSenseUserContext
# Create the user attributes
user_attributes = {
"Browser": "Chrome",
"Device": "Desktop"
}
# Create the PageSenseUserContext object
user_context = PageSenseUserContext(
user_id="USER_001",
user_attributes=user_attributes
)
# Track the Goal
pagesense_client.track_goal(
goal_name,
user_context
)
How It Works
When the Track Goal API is called, the SDK:
Tracks the goal conversion at the project level.
Determines whether the goal is associated with any active FullStack A/B Test experiments.
Checks whether the visitor has qualified for those experiments.
Automatically attributes the goal conversion to every applicable experiment.
Notes
Project-level goal tracking always occurs.
Experiment attribution is automatic.
A goal can be attributed to multiple experiments.
No experiment identifier is required when calling the API.
Best Practices
Track goals immediately after the business event occurs.
Reuse the same PageSenseUserContext used during experiment evaluation.
Ensure the goal name exactly matches the goal configured in PageSense.