Class: SnowplowTracker::Timestamp

  • Object
show all
Defined in:


Creates timestamps for events. Timestamps are counted in milliseconds since the Unix epoch (( * 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.

  1. 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 as dtm in the event.
  2. Manually create a DeviceTimestamp (e.g., and provide this to the #track_x_event method. This will still be recorded as dtm in the event.
  3. Provide a TrueTimestamp object to the track_x_event method (e.g. This will result in a ttm 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.

Direct Known Subclasses

DeviceTimestamp, TrueTimestamp