Track Goal

Track Goal

The trackGoal() method is used to record goal conversions for Full Stack A/B Testing experiments in PageSense.  It records the conversion events in PageSense only for the users who qualify for the experiment.
This API can be invoked with or without user attributes, depending on how your experiment’s audience targeting rules are configured.

Calling the Method

  1. // Track the goal conversion for a Full Stack A/B Test experiment
  2. $pageSenseClient->trackGoal($experimentName, $userId, $goalName, $userAttributes);

Method Parameters

Parameter

Type

Description

experimentName

string

The name of the experiment where the goal is defined.

userId

string

A unique identifier for the user.

goalName

string

The name of the goal being tracked.

userAttributes

array

(Optional) Associative array of user attributes used for audience targeting and segmentation.


Prerequisites  

While invoking this method, ensure that:

  • The experiment is activated in the web page where the goal is being tracked.

  • The method is invoked only when the conversion conditions associated with the goal are satisfied.

Return Behavior  

  • If the user qualifies for the experiment, the goal conversion is recorded and sent to PageSense server.

  • If the user does not qualify, or falls outside the experiment’s traffic allocation, the API silently ignores the conversion request.

This ensures conversions are tracked only for the users who are part of the A/B Test experiment.
 

Example Code

  1. use Zoho\PageSense\PageSenseClient;
  2. // Define user attributes
  3. $userAttributes = [
  4.     'Browser' => 'Chrome',
  5.     'Device' => 'Desktop',
  6.     'OS' => 'Windows 10'];
  7. // Track goal conversion for a Full Stack experiment
  8. $pageSenseClient->trackGoal($experimentName, $userId, $goalName, $userAttributes);

How the API Works  

When trackGoal() method is invoked, it follows a structured validation process before recording the goal conversion in PageSense:

1. Audience Targeting  

The API checks whether the user qualifies for the experiment based on audience targeting conditions defined in PageSense.

  • These conditions typically include user attributes such as browser, device type, OS, or any custom fields passed in the user attributes.

  • If the user attributes match the audience targeting condition, evaluation continues.

  • If the user attributes do not match the audience targeting condition, the goal conversion details will not be sent to PageSense.

2. User Qualification  

The API next verifies whether the user falls within the experiment’s traffic allocation range.

  • If the User Storage Service is enabled, the SDK retrieves any previously assigned variation for the user (ensuring consistent tracking across sessions).

  • If no variation is stored, a new one is allocated using deterministic bucketing (based on hashing).

  • The SDK then applies the MurmurHash algorithm to the user’s ID (userId) to produce a numeric hash between 0–9999.

  • Each variation in the experiment is assigned a unique hash range corresponding to its traffic percentage.

Example:

Variation

Hash Range

Original

0 – 2000

Variation 1

2001 – 4000

Variation 2

4001 – 6000

If the user’s hash value falls within one of these ranges, the user qualifies and the goal event is tracked. If it falls outside, no event is sent.

3. Tracking and Analytics  

Once qualification succeeds and the goal condition is triggered:

  • The SDK packages the experiment name, user ID, goal name, and variation ID.

  • It sends this conversion event to the PageSense backend using a secure HTTPS request.

  • This data powers conversion metrics, probability of win, and confidence reports in the experiment dashboard.

4. Return Behavior  

Condition

SDK Behavior

User qualifies and goal achieved

Sends goal event to PageSense

User doesn’t qualify

Ignores call silently

Network error / invalid SDK key

Logs error (if logging enabled), does not retry automatically

 

Using trackGoal() Without User Attributes  

You can also call the API without providing user attributes.

Calling the Method

  1. // Track goal conversion without user attributes
  2. $pageSenseClient->trackGoal($experimentName, $userId, $goalName);

How It Works  

  • Only Experiment Name, User Id, and Goal Name are required.

  • Audience targeting still runs, but users get qualified for the experiment only if the audience targeting condition “All Visitors”. For experiments with specific audience targeting rules (e.g., device = mobile), users will not qualify for the experiments as there are no user attributes passed.

  • If user is qualified for the experiment, the API uses the MurmurHash algorithm to determine the variation and record the goal against the variation allocated.

  • If the user is not qualified for the experiment, no conversion event will be triggered.

Best Practices  

  • Always call trackGoal() API immediately after a conversion event.

  • Use consistent User Id values across all SDK methods for deterministic behavior.

  • If your backend processes conversions asynchronously via jobs or queues, ensure the SDK call is included in the post-processing stage.

  • Handle silent no-ops gracefully — not all users will qualify for tracking.

For high-throughput apps, batch conversions where possible to reduce API overhead.

We hope this documentation helps make the process easy for you. Please feel free to reach out to us anytime by dropping an email to support@zohopagesense.com if you need more explanation or have any questions.