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.

Classes

Tracking

The main class: match a campaign tracker in the request, count the visit, log the hit, and redirect to the campaign homepage.

Functions

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

PropertyTypeDescription
$campaign->namestringThe campaign name (readonly).
$campaign->codestringThe campaign tracker code (readonly).
$campaign->homepageUrlstringThe url visitors are redirected to (readonly).
$campaign->addedCalendarDateTimeDataWhen the campaign was added (readonly).
Functions

__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.

NameTypeDescription
$namestringThe campaign name.
$codestringThe campaign tracker code.
$homepageUrlstringThe url visitors are redirected to.
$addedCalendarDateTimeDataWhen 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.

Functions

fromRow

TrackingCampaignDatabase::fromRow(stdClass $row): TrackingCampaignData

Build a campaign data object from a database row, converting the stored timestamp to a datetime.

NameTypeDescription
$rowstdClassThe 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.

NameTypeDescription
$trackerStringstringThe 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.

NameTypeDescription
$modulestringThe module the event belongs to.
$eventstringThe 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.

NameTypeDescription
$eventIdintThe id of the event the entry belongs to.
$keystringThe entry key.
$valueintThe 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.

NameTypeDescription
$eventIdintThe id of the event the entry belongs to.
$keystringThe entry key.
$valuestringThe 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.

NameTypeDescription
$campaignCodestringThe 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

PropertyTypeDescription
TrackingLog::$globalIntegersarrayInteger entries held for the next event, keyed by name.
TrackingLog::$globalStringsarrayText entries held for the next event, keyed by name.
Functions

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.

NameTypeDescription
$modulestringThe module the event belongs to.
$eventstringThe event name.
$callbackcallableA 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.

NameTypeDescription
$keystringThe entry key.
$valueintThe 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.

NameTypeDescription
$keystringThe entry key.
$valuestringThe text value.

Returns void