Read on below the jump for:
The Scala Analytics SDK makes it significantly easier to build applications that consume Snowplow enriched data directly from Kinesis or S3.
The Snowplow enriched event is a relatively complex TSV string containing self-describing JSONs. Rather than work with this structure directly, Snowplow analytics SDKs ship with event transformers, which translate the Snowplow enriched event format into something more convenient for engineers and analysts.
As the Snowplow enriched event format evolves towards a cleaner Apache Avro-based structure, we will be updating this Analytics SDK to maintain compatibility across different enriched event versions.
Working with the Snowplow Scala Analytics SDK therefore has two major advantages over working with Snowplow enriched events directly:
Currently the Analytics SDK for Scala ships with one event transformer: the JSON Event Transformer. Let’s check this out next.
The JSON Event Transformer takes a Snowplow enriched event and converts it into a JSON ready for further processing. This transformer was adapted from the code used to load Snowplow events into Elasticsearch in the Kinesis real-time pipeline.
The JSON Event Transformer converts a Snowplow enriched event into a single JSON like so:
The most complex piece of processing is the handling of the self-describing JSONs found in the enriched event’s
derived_contexts fields. All self-describing JSONs found in the event are flattened into top-level plain (i.e. not self-describing) objects within the enriched event JSON.
For example, if an enriched event contained a
com.snowplowanalytics.snowplow/link_click/jsonschema/1-0-1, then the final JSON would contain:
For more information, check out the Scala Analytics SDK wiki page.
The latest version of Snowplow Scala Analytics SDK is 0.1.0, which is cross-built against Scala 2.10.x and 2.11.x.
If you’re using SBT, add the following lines to your build file:
Note the double percent (
%%) between the group and artifactId. This will ensure that you get the right package for your Scala version.
The Scala Analytics SDK is a great fit for performing Snowplow event data modeling in Apache Spark and Spark Streaming.
Here’s the code we use internally for our own data modeling jobs:
The Scala Analytics SDK is a great fit for performing analytics-on-write, monitoring or alerting on Snowplow event streams using AWS Lambda.
Here’s some sample code for transforming enriched events into JSON inside a Scala Lambda:
We are hugely excited about developing our analytics SDK initiative in four directions:
If you would like to help out, please get in touch! In particular, we’d love to get contributions to the official Python or Node.js Analytics SDKs.
We are working on a new section of the Snowplow wiki dedicated to our Analytics SDKs.
In the meantime, if you have any questions or run into any problems, please raise an issue or get in touch with us through the usual channels.