Datetime Enrichment

When you are trying to do analysis with Datetimes, sometimes you want to break down the dates or times into more properties, like day of the week or month. This is where the Datetime enrichment can be especially useful. It allows you to enrich a Datetime property into more interesting properties.

If you want to start using the enrichment right now while tracking pageviews, clicks, and form submissions, check out the Web Auto-Collector.

When this enrichment is being used, you can do analysis on 11 different properties:

Property Description
millisecond The millisecond of the datetime provided.
day_of_week_string The day of week in string form. ie: “Saturday”
hour The universal time (00:00 - 24:00) hour of the datetime provided.
timezone_offset The numerical timezone offset from UTC of the datetime provided. ie: 0
day_of_month The day of month of the datetime provided.
day_of_week The day of week in numerical form: ie: 5
month The month of the datetime provided
second The second of the datetime provided
week The week of the datetime provided
year The year of the datetime provided
minute The minute of the datetime provided

To Activate Datetime Enrichment

The parameters for the Datetime enrichment are as follows:

Parameter Description
name “keen:date_time_parser”
input An object with a key of “date_time” and a value of the name of the property containing a datetime to parse.
{ "date_time": "property.containing.datetime" }
output A property name describing where the produced object should be stored.

Your Event Data Model

To activate the enrichment, include the keen.addons object in your data model as seen below:

{
  "keen" : {
    "timestamp": "2016-05-21T16:36:40.092Z",
    "addons": [
      {
        "name": "keen:date_time_parser",
        "input": {
          "date_time": "keen.timestamp"                                
        },
        "output": "timestamp_info"
      }
    ]
  }
}

In this example, we are setting keen.timestamp ourselves. keen.timestamp will use system time when we receive the event if it is not set. You can pass in the keen.timestamp or any Datetime value into "date_time". It supports ISO-8601 timestamps as well as unix timestamps.

The example above will create an output that looks like this:

{
  "keen": {
    "timestamp": "2016-05-21T16:36:40.092Z"
  },
  "timestamp_info": {
    "millisecond": 92,
    "day_of_week_string": "Saturday",
    "hour": 16,
    "timezone_offset": 0,
    "day_of_month": 21,
    "day_of_week": 6,
    "month": 5,
    "second": 40,
    "week": 20,
    "year": 2016,
    "minute": 36
  }
}

It is also possible to enrich multiple Datetimes, like in this example below:

{
  "checkout_datetime" : "2016-05-21T16:36:40.092Z",
  "keen" : {
    "addons": [
      {
        "name": "keen:date_time_parser",
        "input": {
          "date_time": "keen.timestamp"                                
        },
        "output": "timestamp_info"
      },
      {
        "name": "keen:date_time_parser",
        "input": {
          "date_time": "checkout_datetime"                                
        },
        "output": "checkout_timestamp_info"
      }
    ]
  }
}

You can also find the API Reference section for this enrichment here.

Examples

You might want to see if there’s a trend for which day of the week has the highest traffic.

Count pageviews with day_of_week_string group_by:

Group by day_of_week_string piechart

Or you might want to see if there’s a trend for what hour of the day has the highest traffic.

Count pageviews with hour_of_day group_by:

Group by hour_of_day