Class: SnowplowTracker::Timestamp
- Inherits:
-
Object
- Object
- SnowplowTracker::Timestamp
- Defined in:
- lib/snowplow-tracker/timestamp.rb
Overview
Creates timestamps for events. Timestamps are counted in milliseconds since
the Unix epoch ((Time.now.to_f * 1000).to_i
).
Snowplow events accrue timestamps as they are processed. When an event is
first generated by a Tracker, it has the raw event property dtm
("device timestamp"; dvce_created_tstamp
in the processed event)
or ttm
("true timestamp";true_tstamp
in the processed event). These two
timestamps are set using the Timestamp subclasses DeviceTimestamp and
TrueTimestamp. The Emitter adds a stm
("sent timestamp";
dvce_sent_tstamp
) property to the event just before sending it to the
collector. These timestamps are all processed into UTC time.
Events can have either a device timestamp or a true timestamp, not both. By
default, the #track_x_event
methods create a DeviceTimestamp. In some
circumstances, the device timestamp may be inaccurate. There are three
methods to override the default device timestamp value when the event is
created.
- Provide your own calculated timestamp, as a Num (e.g.
1633596554978
), to the#track_x_event
method. This will be converted into a DeviceTimestamp by the Tracker, and will still be recorded asdtm
in the event. - Manually create a DeviceTimestamp (e.g.
SnowplowTracker::DeviceTimestamp.new(1633596554978)
), and provide this to the#track_x_event
method. This will still be recorded asdtm
in the event. - Provide a TrueTimestamp object to the
track_x_event
method (e.g.SnowplowTracker::TrueTimestamp.new(1633596554978)
). This will result in attm
field in the event.
The timestamps that are added to the event once it has been emitted are not
the responsibility of this class. The collector receives the event and adds a
collector_tstamp
. A later part of the pipeline adds the etl_tstamp
when
the event enrichment has finished.
When DeviceTimestamp is used, a derived_tstamp
is also calculated and
added to the event. This timestamp attempts to take latency and possible
inaccuracy of the device clock into account. It is calculated by
collector_tstamp - (dvce_sent_tstamp - dvce_created_tstamp)
. When
TrueTimestamp is used, the derived_stamp
will be the same as
true_tstamp
.