Sauce Analytics

Around the time of iOS 14 (Sept 2020), Apple and other companies started to crack down hard on user privacy and data use. Handing over your user’s keys to 3rd party analytics provider started to look like a bad idea for two reasons:

  • A risk these APIs would be blocked by iOS in the future
  • Companies were found to be misusing a your user’s data and selling to other companies

In-House Analytics

For these reasons, we began to experiment with handling simple analytics in-house. We set up an API and stored the data with Google Big Query.

Data

We store the following data in each request:

NameDescription
user_agentThe browsers user agent string
platformThe Platform the request came from e.g. Windows
osThe OS the request came from e.g. iOS 16.3.1
browserThe specific browser e.g. Mobile Safari UI/WKWebView
browser_versionVersion of the browser e.g. 16.3.1
environmenta string representing the env of your app e.g. staging or production
app_nameUnique name for the app
app_versionVersion number of the app the request came from
app_hashHash of the last commit
user_id(Optional) a unique string or number to represent the user
client_ipThe IP the request came from
global_sequenceThis incrementing number will help detect the sequence of requests in a single users session
event_timeThe time the request was made

Analytics data can be stored in two tables:

Visits

This table stores a row for each visit a user makes to an app route. As well as the standard Data outlined above. Visits also store:

NameDescription
titleA unique string to represent the route the user has visited
nameA full URL including route/query params
visit_sequenceThis incrementing number will help detect the sequence of visit requests in a single users session

Events

This table stores a row each time the user triggers an event of some kind in your app. This may be:

  • Tapping a button
  • Receiving a validation error
  • Filtering a table

As well as the standard Data outlined above. Events also store:

NameDescription
nameA unique string to represent the event e.g. login. success
data(optional) A JSON object containing any data related to the event
event_sequenceThis incrementing number will help detect the sequence of event requests in a single users session

API

The API for collection data contains two endpoints. Check out the existing ember-analytic-sauce for a guide on how you could use the API in other frameworks.

Visit

Here’s an example of a request made from the sauce cupboard to log a visit

POST https://analytics.sauce.construction/visits

Data:

{
  "environment": "production",
  "appName": "cupboard",
  "appVersion": "2.1.1",
  "appHash": "43f9f138",
  "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36",
  "sessionId": "i6j27xs3ndui1x9injpd",
  "userId": null,
  "viewSequence": 1,
  "globalSequence": 1,
  "name": "/",
  "title": "internal.index"
}

Event

Here’s an example of a request made from the sauce cupboards to log a search event

POST https://analytics.sauce.construction/events

{
   "environment":"production",
   "appName":"cupboard",
   "appVersion":"2.1.1",
   "appHash":"43f9f138",
   "userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36",
   "sessionId":"i6j27xs3ndui1x9injpd",
   "userId":null,
   "viewSequence":1,
   "globalSequence":4,
   "name":"cupboard.search",
   "title":"internal.index",
   "data":{
      "term":"til",
      "results":[
         "Anti-Bribery Policy",
         "Today I Learnt",
         ...
      ],
      "number":51
   }
}

Analysis

The easiest way to analyse collected analytics is via Google Looker Studio (Formally Data Studio).

Ensure you filter results by app_name and environment and away you go! Reports can be locked down to certain user accounts and shared/embedded in portals and cms platforms.

When connecting a data source in Looker Studio select BigQuery > SauceAnalytics-Prod

Check out this example of an analytics dashboard with Google Looker Studio.

Jim Wardlaw

Developer, Designer, UX Zealot. Ember & Tailwind