Overview
The PageSense Python SDK supports revenue goal tracking through the Track Goal API by allowing you to pass additional goal information using the goal_properties parameter. Revenue tracking enables you to measure the monetary impact of your FullStack A/B Test experiments and analyse revenue generated by different experiment variations. In addition to recording revenue at the project level, the SDK automatically attributes the revenue conversion to all eligible active experiments associated with the tracked goal for which the visitor has qualified. Revenue values are provided using GoalProperty.REVENUE.
When to Use
Use revenue goal tracking whenever a visitor completes a transaction or performs an action that generates measurable business value.
Typical scenarios include:
Method Signature
track_goal(
goal_name: str,
user_context: PageSenseUserContext,
goal_properties: dict[GoalProperty, str]
)
Parameters
Parameter | Type | Required | Description |
goal_name | str | Yes | Name of the configured revenue goal. |
user_context | PageSenseUserContext | Yes | Visitor information used for goal attribution. |
goal_properties | dict[GoalProperty, str] | Yes | Dictionary containing the revenue goal properties. |
Return Value
Type | Description |
None | This API does not return a value. |
Revenue Goal Properties
The Python SDK currently supports the following goal property.
Goal Property | Value Type | Description |
GoalProperty.REVENUE | str | Revenue amount associated with the goal conversion. |
Note: Goal property values must always be provided as a string.
Revenue values must be converted to the smallest currency unit before being passed to the SDK. To track the revenue value for a revenue goal,
Multiply the revenue value by 100.
Convert the resulting value to a string.
Pass the resulting value using GoalProperty.REVENUE.
This approach avoids floating-point precision issues and ensures consistent revenue tracking across different currencies.
For example:
Revenue Amount | Value Passed to SDK |
$25.99 | "2599" |
€149.95 | "14995" |
Usage Example
from pagesense import GoalProperty
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
)
# Creae the Revenue Goal propety
goal_properties = {
GoalProperty.REVENUE: "1999"
}
# Track the Goal
pagesense_client.track_goal(
goal_name,
user_context,
goal_properties
)
How It Works
When a revenue goal is tracked, the SDK performs the following operations:
Records the revenue goal at the project level.
Identifies all active FullStack A/B Test experiments associated with the specified goal.
Determines whether the visitor has qualified for each experiment.
Automatically attributes the revenue conversion to every applicable experiment.
Sends the revenue information to the PageSense server for reporting and analysis.
No additional API calls are required for experiment-level revenue tracking.
Notes
Revenue tracking uses the same track_goal() API.
Revenue values must be passed using GoalProperty.REVENUE.
Goal property values must be strings.
Revenue should always be converted to the smallest currency unit before tracking.
Revenue attribution to experiments is performed automatically by the SDK.
Best Practices
Track the revenue goal immediately after the transaction is successfully completed.
Reuse the same PageSenseUserContext that was used during experiment evaluation.
Ensure the configured goal name exactly matches the revenue goal configured in PageSense.
Always convert revenue values to the smallest currency unit before passing them to the SDK.
Pass only valid transaction amounts to ensure accurate revenue reporting.