Overview and Schema - Redshift

Heap Connect lets you directly access your Heap data using SQL in your Redshift warehouse. You can run ad-hoc analyses, connect to BI tools such as Tableau, or join the raw Heap data with your own internal data sources.

Best of all, we automatically keep the data up-to-date and optimize its performance for you. Define an event within the Heap interface, and in just a few hours, you'll be able to query it retroactively in a clean SQL format.

Heap Connect is available in our enterprise tier. To get started, email us at sales@heapanalytics.com, and we'll be in touch shortly. You can also check out our guide here to look at some common use cases and queries.

This recorded webinar provides everything you need to know about getting data out of Heap.

Setup

Heap Connect can sync data to Amazon Redshift. In order to get started, you'll need to choose one of two options:

  • Heap hosts the Redshift cluster for you. We'll provision a Redshift cluster, manage the details of configuration ourselves, and provide you with access credentials.
  • Host the Redshift cluster yourself. You'll need to grant us access to an existing Redshift cluster. You can do so by sending us its credentials: the cluster's hostname, port, username, password, and public key. You'll also need to whitelist our IP if your cluster isn't exposed to the public.

In both scenarios, you need to be careful that any changes you make to the cluster do not interfere with Heap's dynamic schema updates.

Schema

All data in your account is hosted within a single Redshift cluster.

Data in separate environments are stored in separate schemas. The schemas are named using the project name, then an underscore, followed by the environment name. For instance, each table in your main production environment will be part of the main_production schema, while the tables in the development environment of a project named "My iOS App" will be in a schema called my_ios_app_development.

For each environment, Heap will create the following tables:

  1. One users table.
  2. One sessions table.
  3. One pageviews table.
  4. One table for each event you've defined in the Heap interface and have syncing.
  5. One view for each segment you've defined in the Heap interface and have syncing.
  6. One all_events table which contains the builtin pageview event and all defined or custom events synced to Redshift.
  7. One _sync_info table.
  8. One user_migrations table which lists all instances of merging and migrating users.

These tables have a dynamic schema that auto-update to reflect any new events or properties you've tracked.

Users Table

This table is called users and resides under the projectname_environmentname schema. It contains a row for each user in the environment. The column schema is:

Column Name Type Description
user_id BIGINT Unique ID of user, randomly generated by Heap.
identity TEXT User's username or other unique token, passed via heap.identify API. Must be unique.
handle TEXT User's username or other unique token, passed in via heap.addUserProperties API.
email TEXT User's email address, passed in via heap.addUserProperties API.
joindate TIMESTAMP UTC timestamp when the user was first seen.
last_modified TIMESTAMP UTC timestamp when the user's data was last modified.
user properties… TEXT There will be one column for every unique user property you've sent via the heap.addUserProperties API (name, gender, account status, etc). The column type is automatically inferred from the underlying property values.

Sessions Table

For web, a session ends after 30 minutes of inactivity from the user. For iOS, a session ends after your app has entered the background. The sessions table has the following schema:

Column Name Type Library Description
event_id BIGINT All Unique ID of associated session event, randomly generated by Heap used internally by Heap for data syncing.
user_id BIGINT All Unique ID of associated user, randomly generated by Heap.
session_id BIGINT All Unique ID of associated session, randomly generated by Heap.
time TIMESTAMP All UTC timestamp when session started.
library TEXT All Version of Heap library which initiated the session. Can be one of "web" or "iOS".
platform TEXT Web iOS User's operating system.
device_type TEXT Web iOS Device type, which can be one of "Mobile", "Tablet", or "Desktop".
country TEXT Web iOS Country in which user session occurred, based on IP.
region TEXT Web iOS Region in which user session occurred, based on IP.
city TEXT Web iOS City in which user session occurred, based on IP.
IP TEXT Web iOS The IP address for the session, which is used for determining geolocation.
referrer TEXT Web URL that linked to your site and initiated the session. If the user navigated directly to your site, or referral headers were stripped, then this value will appear as direct.
landing_page TEXT Web URL of the first pageview of the session.
browser TEXT Web User's browser.
search_keyword TEXT Web Search term that brought the user to your site.
utm_source TEXT Web GA-based utm_source tag associated with the session's initial pageview.
utm_campaign TEXT Web GA-based utm_campaign tag associated with the session's initial pageview.
utm_medium TEXT Web GA-based utm_medium tag associated with the session's initial pageview.
utm_term TEXT Web GA-based utm_term tag associated with the session's initial pageview.
utm_content TEXT Web GA-based utm_content tag associated with the session's initial pageview.
device TEXT iOS User's device model.
carrier TEXT iOS User's mobile carrier.
app_name TEXT iOS Current name of iOS app, as determined by CFBundleName.
app_version TEXT iOS Current version of iOS app, as determined by CFBundleShortVersionString.

Pageviews Table

Heap will create a table that contains every page view by default.

Column Name Type Library Description
event_id BIGINT All Unique ID of associated pageview event.
user_id BIGINT All Unique ID of associated user, randomly generated by Heap.
session_id BIGINT All Unique ID of associated session, randomly generated by Heap.
session_time TIMESTAMP All Timestamp when session started. This value is primarily for Heap's internal use and drifts on events. It shouldn't be relied on for analysis.
time TIMESTAMP All UTC timestamp when the pageview occurred.
library TEXT All Version of Heap library which initiated the session. Can be one of "web" or "iOS".
platform TEXT Web iOS User's operating system.
device_type TEXT Web iOS Device type, which can be one of "Mobile", "Tablet", or "Desktop".
country TEXT Web iOS Country in which user session occurred, based on IP.
region TEXT Web iOS Region in which user session occurred, based on IP.
city TEXT Web iOS City in which user session occurred, based on IP.
IP TEXT Web iOS The IP address for the session, which is used for determining geolocation.
referrer TEXT Web URL that linked to your site and initiated the session. If the user navigated directly to your site, or referral headers were stripped, then this value will appear as direct.
landing_page TEXT Web URL of the first pageview of the session.
browser TEXT Web User's browser.
search_keyword TEXT Web Search term that brought the user to your site.
utm_source TEXT Web GA-based utm_source tag associated with the session's initial pageview.
utm_campaign TEXT Web GA-based utm_campaign tag associated with the session's initial pageview.
utm_medium TEXT Web GA-based utm_medium tag associated with the session's initial pageview.
utm_term TEXT Web GA-based utm_term tag associated with the session's initial pageview.
utm_content TEXT Web GA-based utm_content tag associated with the session's initial pageview.
path TEXT Web The path of the pageview.
query TEXT Web The query parameters associated with the pageview.
hash TEXT Web The hash parameters associated with the pageview
title TEXT Web Title of the current page.
device TEXT iOS User's device model.
carrier TEXT iOS User's mobile phone carrier.
app_name TEXT iOS Current name of iOS app, as determined by CFBundleName.
app_version TEXT iOS Current version of iOS app, as determined by CFBundleShortVersionString.
view_controller TEXT iOS Name of the current view controller.
screen_a11y_id TEXT iOS accessibilityIdentifier for the current view controller.
screen_a11y_label TEXT iOS accessibilityLabel for the current view controller.

Event Tables

Heap will create one table for every defined event you've created within the Heap interface.

For each event table, the columns are determined by the version of the Heap library that sent the event, along with any custom properties you may have added via Snapshots or the custom API. For instance, if an event was sent by the Heap iOS library, its SQL table will contain iOS-specific columns like app_version or carrier, but not web-specific columns like landing_page or search_keyword. This helps keep your schema as clean as possible.

The name of these tables will be the event_name itself and reside under the projectname_environmentname schema. To produce the event_name portion, we strip the event name of any non-alphanumeric characters and snake-case the result. For example, an event named "Sign Up - Click Link (Any)" becomes sign_up_click_link_any. (Note that this means it's possible for events to collide into the same table. Make sure your event names are sufficiently distinct!)

Each of these event tables will be fully retroactive, meaning it will contain a row for every occurrence of the event since the day you installed Heap. The column schema is:

Column Name Type Libraries Description
event_id BIGINT All Unique ID of associated event, randomly generated by Heap.
user_id BIGINT All Unique ID of associated user, randomly generated by Heap.
session_id BIGINT All Unique ID of associated session, randomly generated by Heap.
time TIMESTAMP All UTC timestamp when event happened.
session_time TIMESTAMP All Timestamp when session started. This value is primarily for Heap's internal use and drifts on events. It shouldn't be relied on for analysis.
type TEXT All For web auto-tracked events, can be any of view page, click, submit, change, with push state events registered as view page events. For iOS auto-tracked events, can be touch, edit field, or a gesture recognizer you've defined. For custom events, this will be the custom event name.
library TEXT All Version of Heap library on which event occurred. Can be one of "web", "iOS", or "server".
platform TEXT Web iOS User's operating system.
device_type TEXT Web iOS Device type, which can be one of "Mobile", "Tablet", or "Desktop".
country TEXT Web iOS Country in which user session occurred, based on IP.
region TEXT Web iOS Region in which user session occurred, based on IP.
city TEXT Web iOS City in which user session occurred, based on IP.
IP TEXT Web iOS The IP address for the session, which is used for determining geolocation.
referrer TEXT Web URL that linked to your site and initiated the session. If the user navigated directly to your site, or referral headers were stripped, then this value will appear as direct.
landing_page TEXT Web URL of the first pageview of the session.
browser TEXT Web User's browser.
search_keyword TEXT Web Search term that brought the user to your site.
utm_source TEXT Web GA-based utm_source tag associated with the session's initial pageview.
utm_campaign TEXT Web GA-based utm_campaign tag associated with the session's initial pageview.
utm_medium TEXT Web GA-based utm_medium tag associated with the session's initial pageview.
utm_term TEXT Web GA-based utm_term tag associated with the session's initial pageview.
utm_content TEXT Web GA-based utm_content tag associated with the session's initial pageview.
domain TEXT Web Domain including subdomain, e.g. blog.heapanalytics.com.
path TEXT Web Portion of the current URL following your domain, e.g. /docs for heapanalytics.com/docs.
hash TEXT Web Portion of the current URL following the hash sign, e.g. #install for heapanalytics.com/docs#install.
query TEXT Web Query params of the page's current URL, e.g. ?utm_id=1234 for heapanalytics.com?utm_id=1234.
title TEXT Web Title of the current page.
href TEXT Web href property of link (used for clicks on anchor tags).
device TEXT iOS User's device model.
carrier TEXT iOS User's mobile phone carrier.
app_name TEXT iOS Current name of iOS app, as determined by CFBundleName.
app_version TEXT iOS Current version of iOS app, as determined by CFBundleShortVersionString.
action_method TEXT iOS Name of the action method triggered by this event, e.g. loginButtonWasPressed.
view_controller TEXT iOS Name of the current view controller.
screen_a11y_id TEXT iOS accessibilityIdentifier for the current view controller.
screen_a11y_label TEXT iOS accessibilityLabel for the current view controller.
target_view_class TEXT iOS Underlying class name of an iOS action's target, e.g. UITableCellView.
target_view_name TEXT iOS Instance variable name of an iOS action's target, e.g. loginButtonView.
target_a11y_id TEXT iOS accessibilityIdentifier of an iOS action's target.
target_a11y_label TEXT iOS accessibilityLabel of an iOS action's target.
target_text TEXT Web iOS Button text of the event target.
Event properties… TEXT All There will be one column for every unique event property you've attached, either via the heap.track API, the addEventProperties API, or Snapshots. The column type is automatically inferred from the underlying property values.

Segment Views

Heap will create one view for every defined segment you've created within the Heap interface. These views only contain one column (user_id) that you can use to join against all other user information (users or other event tables).

Column Name Type Description
user_id BIGINT Unique ID of associated user, randomly generated by Heap.

All Events Table

Heap will also create a table called all_events, which contains all defined or custom API events you have synced to Redshift, as well as the builtin pageview event. The all_events table will have the following columns.

Column Name Type Description
event_id BIGINT Unique ID of associated event, randomly generated by Heap.
user_id BIGINT Unique ID of associated user, randomly generated by Heap.
session_id BIGINT Unique ID of associated session, randomly generated by Heap.
time TIMESTAMP UTC timestamp when event happened.
event_table_name TEXT Name of the table where similar events can be found.

Sync Info Table

Heap creates a table called _sync_info that contains metadata around the sync process and last updated times.

Column Name Type Description
event_table_name TEXT the event name
sync_started TIMESTAMP a timestamp for when that table began syncing
sync_ended TIMESTAMP a timestamp for when that table completed syncing
synced_to_time TIMESTAMP a timestamp that reflects the most recent occurrence of the event
inserted_row_count BIGINT the number of rows inserted during the most recent sync

User Migrations Table

When a user is identified, a migration occurs to aggregate the data under the new identity. These migrations are recorded in this table.

Column Name Type Description
from_user_id BIGINT the migrating user's ID
to_user_id BIGINT the destination user's ID
time TIMESTAMP a timestamp for when the migration occurred

Data Syncing

Your Redshift cluster periodically syncs to your raw Heap data.

As you define new events and modify existing events, we seamlessly update your cluster schema. This ensures that the data in Redshift is always a clean, accurate representation of your raw data.

In particular, the following changes can happen on each sync:

  • When an event is seen for the first time, we create a new table for that event.
  • When a defined event is modified in the Heap interface, we tear down the existing table for that event, create a new one in its place, and populate the new table.
  • When a custom event property is seen for the first time, we add a new property column to the corresponding event table.
  • When a custom user property is seen for the first time, we add a new user property column to the users table.
  • When user-level properties are updated with heap.addUserProperties, we update corresponding rows in the users table.
  • When an anonymous user gets identified with an existing identity via heap.identify, we "migrate" the user by running an update on the users table and another update on all event tables that reference the anonymous user's user_id.

Performance Optimization

Under the hood, we tune your Redshift schema to ensure that it is as performant as possible. In particular, this means:

  • The sort key on each table is the time field. This ensures that recent data gets accessed more quickly than older data.
  • The distribution key on each table is the user_id field. This collocates user and event data for a given user_id on the same node slice, which ensures that user-level joins between the users table and event tables are as performant as possible.
  • Automatic compression is enabled. This ensures that columnar data is optimally encoded, which reduces disk I/O and improves query performance.

To learn more about concepts such as column compression and node distribution, take a look at the Amazon Redshift docs.