Tracking
Redirect campaign trackers to their homepage while counting visits, and record named events with keyed integer and text log entries in the database.
This page is a pure reference. For how the framework fits together, see the Guide.
Tracking- route a campaign tracker, count the visit and redirect.TrackingCampaignData- immutable data for a tracking campaign.TrackingCampaignDatabase- read a campaign row from the database.TrackingDatabase- write events, log entries and visit counts.TrackingLog- record an event with keyed integer and text entries.
Tracking
The main class: match a campaign tracker in the request, count the visit, log the hit, and redirect to the campaign homepage.
Route
Tracking::Route(): void
Match a campaign tracker string from the request, count the visit, log the campaign hit, and send a redirect to the campaign homepage. Does nothing when no campaign matches.
Returns void
TrackingCampaignData
Immutable data for a tracking campaign. Fields and constructor only.
Properties
| Property | Type | Description |
|---|---|---|
$campaign->name | string | The campaign name (readonly). |
$campaign->code | string | The campaign tracker code (readonly). |
$campaign->homepageUrl | string | The url visitors are redirected to (readonly). |
$campaign->added | CalendarDateTimeData | When the campaign was added (readonly). |
__construct
new TrackingCampaignData(string $name = '', string $code = '', string $homepageUrl = '', CalendarDateTimeData $added = new CalendarDateTimeData())
Create campaign data from a name, tracker code, homepage url and added datetime.
| Name | Type | Description |
|---|---|---|
$name | string | The campaign name. |
$code | string | The campaign tracker code. |
$homepageUrl | string | The url visitors are redirected to. |
$added | CalendarDateTimeData | When the campaign was added. |
Returns TrackingCampaignData
TrackingCampaignDatabase
Read a tracking campaign from the database by its tracker code, and build the campaign data object from a database row.
fromRow
TrackingCampaignDatabase::fromRow(stdClass $row): TrackingCampaignData
Build a campaign data object from a database row, converting the stored timestamp to a datetime.
| Name | Type | Description |
|---|---|---|
$row | stdClass | The database row to read. |
Returns TrackingCampaignData The campaign data.
Get
TrackingCampaignDatabase::Get(string $trackerString): TrackingCampaignData
Read the campaign whose code matches the given tracker string.
| Name | Type | Description |
|---|---|---|
$trackerString | string | The campaign tracker code to look up. |
Returns TrackingCampaignData The matching campaign.
TrackingDatabase
Write tracking rows to the database: create an event, add keyed integer or text log entries against an event, and increment a campaign's visit count.
CreateEvent
TrackingDatabase::CreateEvent(string $module, string $event): int
Insert a tracking event row for a module and event name, stamped with the current date and timestamp.
| Name | Type | Description |
|---|---|---|
$module | string | The module the event belongs to. |
$event | string | The event name. |
Returns int The id of the new event row.
CreateIntegerLog
TrackingDatabase::CreateIntegerLog(int $eventId, string $key, int $value): int
Insert a keyed integer log entry against an event.
| Name | Type | Description |
|---|---|---|
$eventId | int | The id of the event the entry belongs to. |
$key | string | The entry key. |
$value | int | The integer value. |
Returns int The id of the new log row.
CreateTextLog
TrackingDatabase::CreateTextLog(int $eventId, string $key, string $value): int
Insert a keyed text log entry against an event.
| Name | Type | Description |
|---|---|---|
$eventId | int | The id of the event the entry belongs to. |
$key | string | The entry key. |
$value | string | The text value. |
Returns int The id of the new log row.
Hit
TrackingDatabase::Hit(string $campaignCode): void
Increment the visit count of the campaign with the given code.
| Name | Type | Description |
|---|---|---|
$campaignCode | string | The code of the campaign to count a visit for. |
Returns void
TrackingLog
Record an event and, within its callback, attach keyed integer and text entries. Entries added outside an event are held as globals and written when the next event runs.
Properties
| Property | Type | Description |
|---|---|---|
TrackingLog::$globalIntegers | array | Integer entries held for the next event, keyed by name. |
TrackingLog::$globalStrings | array | Text entries held for the next event, keyed by name. |
Event
TrackingLog::Event(string $module, string $event, callable $callback): void
Create an event, run the callback so it can add integer and text entries against it, then write any held global entries. Nested events restore the previous event when they finish.
| Name | Type | Description |
|---|---|---|
$module | string | The module the event belongs to. |
$event | string | The event name. |
$callback | callable | A callback run while the event is current, to add entries. |
Returns void
Integer
TrackingLog::Integer(string $key, int $value): void
Add a keyed integer entry to the current event, or hold it as a global when no event is current.
| Name | Type | Description |
|---|---|---|
$key | string | The entry key. |
$value | int | The integer value. |
Returns void
Text
TrackingLog::Text(string $key, string $value): void
Add a keyed text entry to the current event, or hold it as a global when no event is current.
| Name | Type | Description |
|---|---|---|
$key | string | The entry key. |
$value | string | The text value. |
Returns void