Skip to main content

Snowplow Mobile Models

caution

This page is auto-generated from our dbt packages, some information may be incomplete

Snowplow Mobileโ€‹

Snowplow Mobile App Errorsโ€‹

models/optional_modules/app_errors/snowplow_mobile_app_errors.sql

Description

This derived table contains all app errors and should be the end point for any analysis or BI tools looking to investigate app errors. This is an optional table that will be empty if the app_errors module is not enabled.

Details

Columns
Column NameDescription
event_idA UUID for each event e.g. c6ef3124-b53a-4b13-a233-0088f79dcbcb.
app_idApplication ID e.g. angry-birds is used to distinguish different applications that are being tracked by the same Snowplow stack, e.g. production versus dev.
user_idUnique ID set by business e.g. jon.doe@email.com.
device_user_idUnique device user id.
network_useridUser ID set by Snowplow using 3rd party cookie e.g. ecdff4d0-9175-40ac-a8bb-325c49733607.
session_idA visit / session UUID e.g. c6ef3124-b53a-4b13-a233-0088f79dcbcb.
session_indexA visit / session index e.g. 3.
previous_session_idA previous visit / session index e.g. 3.
session_first_event_idA first visit / session index e.g. 3.
dvce_created_tstampTimestamp event was recorded on the client device e.g. 2013-11-26 00:03:57.885.
collector_tstampTime stamp for the event recorded by the collector e.g. 2013-11-26 00:02:05.
derived_tstampTimestamp making allowance for innaccurate device clock e.g. 2013-11-26 00:02:04.
model_tstampThe current timestamp when the model processed this row.
platformPlatform e.g. web.
dvce_screenwidthScreen width in pixels e.g. 1900.
dvce_screenheightScreen height in pixels e.g. 1024.
device_manufacturerManufacturer name of the device eg. Apple.
device_modelModel of the mobile device.
os_typeType of OS running on the mobile device.
os_versionOperation system full version.
android_idfaIdentifier for Advertisers for Android devices.
apple_idfaIdentifier for Advertisers for Apple devices.
apple_idfvIdentifier for Vendors for Apple devices.
open_idfaIdentifier for Vendors for Open devices.
screen_idA UUID for each screen e.g. 738f1fbc-5298-46fa-9474-bc0a65f014ab.
screen_nameThe name set for a specific screen, e.g. DemoScreenName.
screen_activityThe name of the Activity element in the screen.
screen_fragmentThe name of the screen fragment (also known as an anchor).
screen_top_view_controllerThe name of the root view controller.
screen_typeThe type of screen that was viewed.
screen_view_controllerThe name of the view controller.
device_latitudeLatitude coordinates for device location.
device_longitudeLongitude coordinates for device location.
device_latitude_longitude_accuracyAccuracy of Latitude and Longitude coordinates for device location.
device_altitudeAltitude coordinates for device location.
device_altitude_accuracyAccuracy of device altitude coordinates.
device_bearingHorizontal angle between device and true north.
device_speedMobile device speed.
geo_countryISO 3166-1 code for the country the visitor is located in e.g. GB, US.
geo_regionISO-3166-2 code for country region the visitor is in e.g. I9, TX.
geo_cityCity the visitor is in e.g. New York, London.
geo_zipcodePostcode the visitor is in e.g. 94109.
geo_latitudeVisitor location latitude e.g. 37.443604.
geo_longitudeVisitor location longitude e.g. -122.4124.
geo_region_nameVisitor region name e.g. Florida.
geo_timezoneVisitor timezone name e.g. Europe/London.
user_ipaddressUser IP address e.g. 92.231.54.234.
useragentRaw useragent.
carrierCarrier serivce provider used within device.
network_technologytechnology used by the network provider of the device.
network_typeType of network eg. 3G.
buildThe build of the application.
versionThe application version.
event_index_in_sessionA session index of the event.
messageThe error message that the application showed when the app error occurred.
programming_languageThe name of the programming language used in which the app error occured.
class_nameThe name of the class where the app error occurred.
exception_nameThe name of the exception encountered in the app error.
is_fatalA boolean to describe whether the app error was fatal or not.
line_numberThe line number in the code where the app error occured.
stack_traceThe full stack trace that was presented when the app error occured.
thread_idThe ID of the thread in which the app error occurred.
thread_nameThe name of the process that ran the thread when the app error occurred.
Code
Source
{{
config(
materialized="incremental",
unique_key='event_id',
upsert_date_key='derived_tstamp',
sort='derived_tstamp',
dist='event_id',
partition_by = snowplow_utils.get_value_by_target_type(bigquery_val={
"field": "derived_tstamp",
"data_type": "timestamp"
}, databricks_val='derived_tstamp_date'),
cluster_by=snowplow_mobile.cluster_by_fields_app_errors(),
tags=["derived"],
enabled=var("snowplow__enable_app_errors_module", false),
sql_header=snowplow_utils.set_query_tag(var('snowplow__query_tag', 'snowplow_dbt')),
tblproperties={
'delta.autoOptimize.optimizeWrite' : 'true',
'delta.autoOptimize.autoCompact' : 'true'
},
snowplow_optimize=true
)
}}


select *
{% if target.type in ['databricks', 'spark'] -%}
, DATE(derived_tstamp) as derived_tstamp_date
{%- endif %}
from {{ ref('snowplow_mobile_app_errors_this_run') }}
where {{ snowplow_utils.is_run_with_new_events('snowplow_mobile') }} --returns false if run doesn't contain new events.

Depends On

Snowplow Mobile App Errors This Runโ€‹

models/optional_modules/app_errors/scratch/<adaptor>/snowplow_mobile_app_errors_this_run.sql

Description

This staging table contains all the app errors for the given run of the Mobile model. This is an optional table that will not be generated if the app_errors module is not enabled.

File Paths

models/optional_modules/app_errors/scratch/bigquery/snowplow_mobile_app_errors_this_run.sql

Details

Columns
Column NameDescription
event_idA UUID for each event e.g. c6ef3124-b53a-4b13-a233-0088f79dcbcb.
app_idApplication ID e.g. angry-birds is used to distinguish different applications that are being tracked by the same Snowplow stack, e.g. production versus dev.
user_idUnique ID set by business e.g. jon.doe@email.com.
device_user_idUnique device user id.
network_useridUser ID set by Snowplow using 3rd party cookie e.g. ecdff4d0-9175-40ac-a8bb-325c49733607.
session_idA visit / session UUID e.g. c6ef3124-b53a-4b13-a233-0088f79dcbcb.
session_indexA visit / session index e.g. 3.
previous_session_idA previous visit / session index e.g. 3.
session_first_event_idA first visit / session index e.g. 3.
dvce_created_tstampTimestamp event was recorded on the client device e.g. 2013-11-26 00:03:57.885.
collector_tstampTime stamp for the event recorded by the collector e.g. 2013-11-26 00:02:05.
derived_tstampTimestamp making allowance for innaccurate device clock e.g. 2013-11-26 00:02:04.
model_tstampThe current timestamp when the model processed this row.
platformPlatform e.g. web.
dvce_screenwidthScreen width in pixels e.g. 1900.
dvce_screenheightScreen height in pixels e.g. 1024.
device_manufacturerManufacturer name of the device eg. Apple.
device_modelModel of the mobile device.
os_typeType of OS running on the mobile device.
os_versionOperation system full version.
android_idfaIdentifier for Advertisers for Android devices.
apple_idfaIdentifier for Advertisers for Apple devices.
apple_idfvIdentifier for Vendors for Apple devices.
open_idfaIdentifier for Vendors for Open devices.
screen_idA UUID for each screen e.g. 738f1fbc-5298-46fa-9474-bc0a65f014ab.
screen_nameThe name set for a specific screen, e.g. DemoScreenName.
screen_activityThe name of the Activity element in the screen.
screen_fragmentThe name of the screen fragment (also known as an anchor).
screen_top_view_controllerThe name of the root view controller.
screen_typeThe type of screen that was viewed.
screen_view_controllerThe name of the view controller.
device_latitudeLatitude coordinates for device location.
device_longitudeLongitude coordinates for device location.
device_latitude_longitude_accuracyAccuracy of Latitude and Longitude coordinates for device location.
device_altitudeAltitude coordinates for device location.
device_altitude_accuracyAccuracy of device altitude coordinates.
device_bearingHorizontal angle between device and true north.
device_speedMobile device speed.
geo_countryISO 3166-1 code for the country the visitor is located in e.g. GB, US.
geo_regionISO-3166-2 code for country region the visitor is in e.g. I9, TX.
geo_cityCity the visitor is in e.g. New York, London.
geo_zipcodePostcode the visitor is in e.g. 94109.
geo_latitudeVisitor location latitude e.g. 37.443604.
geo_longitudeVisitor location longitude e.g. -122.4124.
geo_region_nameVisitor region name e.g. Florida.
geo_timezoneVisitor timezone name e.g. Europe/London.
user_ipaddressUser IP address e.g. 92.231.54.234.
useragentRaw useragent.
carrierCarrier serivce provider used within device.
network_technologytechnology used by the network provider of the device.
network_typeType of network eg. 3G.
buildThe build of the application.
versionThe application version.
event_index_in_sessionA session index of the event.
messageThe error message that the application showed when the app error occurred.
programming_languageThe name of the programming language used in which the app error occured.
class_nameThe name of the class where the app error occurred.
exception_nameThe name of the exception encountered in the app error.
is_fatalA boolean to describe whether the app error was fatal or not.
line_numberThe line number in the code where the app error occured.
stack_traceThe full stack trace that was presented when the app error occured.
thread_idThe ID of the thread in which the app error occurred.
thread_nameThe name of the process that ran the thread when the app error occurred.
Code
Source
{{
config(
tags=["this_run"],
enabled=(var("snowplow__enable_app_errors_module", false) and target.type == 'bigquery' | as_bool())
)
}}

select
e.event_id,

e.app_id,

e.user_id,
e.device_user_id,
e.network_userid,

e.session_id,
e.session_index,
e.previous_session_id,
e.session_first_event_id,

e.dvce_created_tstamp,
e.collector_tstamp,
e.derived_tstamp,
{{ snowplow_utils.current_timestamp_in_utc() }} AS model_tstamp,

e.platform,
e.dvce_screenwidth,
e.dvce_screenheight,
e.device_manufacturer,
e.device_model,
e.os_type,
e.os_version,
e.android_idfa,
e.apple_idfa,
e.apple_idfv,
e.open_idfa,

e.screen_id,
e.screen_name,
e.screen_activity,
e.screen_fragment,
e.screen_top_view_controller,
e.screen_type,
e.screen_view_controller,

e.device_latitude,
e.device_longitude,
e.device_latitude_longitude_accuracy,
e.device_altitude,
e.device_altitude_accuracy,
e.device_bearing,
e.device_speed,
e.geo_country,
e.geo_region,
e.geo_city,
e.geo_zipcode,
e.geo_latitude,
e.geo_longitude,
e.geo_region_name,
e.geo_timezone,

e.user_ipaddress,
e.useragent,

e.carrier,
e.network_technology,
e.network_type,

e.build,
e.version,
e.event_index_in_session,

-- app error events
{{ snowplow_utils.get_optional_fields(
enabled=true,
fields=app_error_context_fields(),
col_prefix='unstruct_event_com_snowplowanalytics_snowplow_application_error_1_',
relation=ref('snowplow_mobile_base_events_this_run'),
relation_alias='e') }}

from {{ ref('snowplow_mobile_base_events_this_run') }} as e

where e.event_name = 'application_error'

Depends On

Snowplow Mobile Base App Contextโ€‹

models/base/scratch/<adaptor>/contexts/snowplow_mobile_base_app_context.sql

Description

This table only exists when working in a Redshift or Postgres warehouse.

This optional table provides extra context on an event level and brings in data surrounding the application's build and version.

File Paths

models/base/scratch/redshift_postgres/contexts/snowplow_mobile_base_app_context.sql

Details

Columns
Column NameDescription
root_idThe corresponding UUID used in the root table.
root_tstampThe timestamp for when this event was produced.
buildThe build of the application.
versionThe application version.
Code
Source
{{
config(
enabled=(var("snowplow__enable_application_context", false)
and target.type in ['redshift','postgres'] | as_bool()),
dist='root_id',
sort='root_tstamp'
)
}}

{%- set lower_limit, upper_limit = snowplow_utils.return_limits_from_model(
ref('snowplow_mobile_base_events_this_run_limits'),
'lower_limit',
'upper_limit') %}
with base as (

select
ac.root_id,
ac.root_tstamp,
ac.build,
ac.version,
row_number() over (partition by root_id order by root_tstamp) dedupe_index

from {{ var("snowplow__application_context") }} ac

where ac.root_tstamp between {{ lower_limit }} and {{ upper_limit }}

)

select *

from base

where dedupe_index = 1

Depends On

Snowplow Mobile Base Events This Runโ€‹

models/base/scratch/<adaptor>/snowplow_mobile_base_events_this_run.sql

Description

For any given run, this table contains all required events to be consumed by subsequent nodes in the Snowplow dbt mob package. This is a cleaned, de-duped dataset, containing all columns from the raw events table as well as having various optional contexts joined-on/unpacked.

Note: This table should be used as the input to any custom modules that require event level data, rather than selecting straight from atomic.events

File Paths

models/base/scratch/bigquery/snowplow_mobile_base_events_this_run.sql

Details

Columns
note

Base event this run table column lists may be incomplete and is missing contexts/unstructs, please check your warehouse for a more accurate column list.

Column NameDescription
screen_idA UUID for each screen e.g. 738f1fbc-5298-46fa-9474-bc0a65f014ab.
screen_nameThe name set for a specific screen, e.g. DemoScreenName.
screen_activityThe name of the Activity element in the screen.
screen_fragmentThe name of the screen fragment (also known as an anchor).
screen_top_view_controllerThe name of the root view controller.
screescreen_top_view_controllern_typeThe type of screen that was viewed.
screen_view_controllerThe name of the view controller.
device_manufacturerManufacturer name of the device eg. Apple.
device_modelModel of the mobile device.
os_typeType of OS running on the mobile device.
os_versionOperation system full version.
android_idfaIdentifier for Advertisers for Android devices.
apple_idfaIdentifier for Advertisers for Apple devices.
apple_idfvIdentifier for Vendors for Apple devices.
carrierCarrier serivce provider used within device.
open_idfaIdentifier for Vendors for Open devices.
network_technologytechnology used by the network provider of the device.
network_typeType of network eg. 3G.
device_latitudeLatitude coordinates for device location.
device_longitudeLongitude coordinates for device location.
device_latitude_longitude_accuracyAccuracy of Latitude and Longitude coordinates for device location.
device_aldevice_latitude_longitude_accuracytitudeAltitude coordinates for device location.
device_altitude_accuracyAccuracy of device altitude coordinates.
device_bearingHorizontal angle between device and true north.
device_speedMobile device speed.
buildThe build of the application.
versionThe application version.
session_idA visit / session UUID e.g. c6ef3124-b53a-4b13-a233-0088f79dcbcb.
session_indexA visit / session index e.g. 3.
previous_session_idA previous visit / session index e.g. 3.
device_user_idUnique device user id.
session_first_event_idA first visit / session index e.g. 3.
app_idApplication ID e.g. angry-birds is used to distinguish different applications that are being tracked by the same Snowplow stack, e.g. production versus dev.
platformPlatform e.g. web.
etl_tstampTimestamp event began ETL e.g. 2017-01-26 00:01:25.292.
collector_tstampTime stamp for the event recorded by the collector e.g. 2013-11-26 00:02:05.
dvce_created_tstampTimestamp event was recorded on the client device e.g. 2013-11-26 00:03:57.885.
eventThe type of event recorded e.g. page_view.
event_idA UUID for each event e.g. c6ef3124-b53a-4b13-a233-0088f79dcbcb.
name_trackerTracker namespace e.g. sp1.
v_trackerTracker version e.g. js-3.0.0.
v_collectorCollector version e.g. ssc-2.1.0-kinesis.
v_etlETL version e.g. snowplow-micro-1.1.0-common-1.4.2.
user_idUnique ID set by business e.g. jon.doe@email.com.
user_ipaddressUser IP address e.g. 92.231.54.234.
network_useridUser ID set by Snowplow using 3rd party cookie e.g. ecdff4d0-9175-40ac-a8bb-325c49733607.
geo_countryISO 3166-1 code for the country the visitor is located in e.g. GB, US.
geo_regionISO-3166-2 code for country region the visitor is in e.g. I9, TX.
geo_cityCity the visitor is in e.g. New York, London.
geo_zipcodePostcode the visitor is in e.g. 94109.
geo_latitudeVisitor location latitude e.g. 37.443604.
geo_longitudeVisitor location longitude e.g. -122.4124.
geo_region_nameVisitor region name e.g. Florida.
ip_ispVisitor's ISP e.g. FDN Communications.
ip_organizationOrganization associated with the visitor's IP address - defaults to ISP name if none is found e.g. Bouygues Telecom.
ip_domainSecond level domain name associated with the visitor's IP address e.g. nuvox.net.
ip_netspeedVisitor's connection type e.g. Cable/DSL.
se_categoryCategory of event e.g. ecomm, video.
se_actionAction performed / event name e.g. add-to-basket, play-video.
se_labelThe object of the action e.g. the ID of the video played or SKU of the product added-to-basket e.g. pbz00123.
se_propertyA property associated with the object of the action e.g. HD, large.
se_valueA value associated with the event / action e.g. the value of goods added-to-basket e.g. 9.99.
tr_orderidOrder ID e.g. #134.
tr_affiliationTransaction affiliation (e.g. store where sale took place) e.g. web.
tr_totalTotal transaction value e.g. 12.99.
tr_taxTotal tax included in transaction value e.g. 3.00.
tr_shippingDelivery cost charged e.g. 0.00.
tr_cityDelivery address, city e.g. London.
tr_stateDelivery address, state e.g. Washington.
tr_countryDelivery address, country e.g. France.
ti_orderidOrder ID e.g. #134.
ti_skuProduct SKU e.g. pbz00123.
ti_nameProduct name e.g. Cone pendulum.
ti_categoryProduct category e.g. New Age.
ti_priceProduct unit price e.g. 9.99.
ti_quantityNumber of product in transaction e.g. 2.
useragentRaw useragent.
dvce_screenwidthScreen width in pixels e.g. 1900.
dvce_screenheightScreen height in pixels e.g. 1024.
tr_currencyCurrency e.g. USD.
tr_total_baseTotal in base currency e.g. 12.99.
tr_tax_baseTotal tax in base currency e.g. 3.00.
tr_shipping_basedecimal Delivery cost in base currency e.g. 0.00.
ti_currencyCurrency e.g. EUR.
ti_price_basedecimal Price in base currency e.g. 9.99.
base_currencyReporting currency e.g. GBP.
geo_timezoneVisitor timezone name e.g. Europe/London.
etl_tagsJSON of tags for this ETL run e.g. โ€œ['prod']โ€.
dvce_sent_tstampWhen the event was sent by the client device e.g. 2013-11-26 00:03:58.032.
derived_tstampTimestamp making allowance for innaccurate device clock e.g. 2013-11-26 00:02:04.
event_vendorWho defined the event e.g. com.acme.
event_nameEvent name e.g. link_click.
event_formatFormat for event e.g. jsonschema.
event_versionVersion of event schema e.g. 1-0-2.
event_fingerprintHash client-set event fields e.g. AADCE520E20C2899F4CED228A79A3083.
true_tstampUser-set โ€œtrue timestampโ€ for the event e.g. 2013-11-26 00:02:04.
event_id_dedupe_indexAn indexing column used for de-duplication of raw events
event_id_dedupe_countA count of the total duplicates of the event, used in Redshift/Postgres for joining entities in some cases
row_count
event_index_in_sessionA session index of the event.
Code
Source
{{
config(
tags=["this_run"]
)
}}

{%- set lower_limit, upper_limit = snowplow_utils.return_limits_from_model(ref('snowplow_mobile_base_sessions_this_run'),
'start_tstamp',
'end_tstamp') %}

{% set session_id = snowplow_mobile.get_session_id_path_sql(relation_alias='a') %}

with events as (
select

-- screen view events
{{ snowplow_utils.get_optional_fields(
enabled=true,
col_prefix='unstruct_event_com_snowplowanalytics_mobile_screen_view_1_',
fields=screen_view_event_fields(),
relation=source('atomic','events'),
relation_alias='a') }},
-- screen context
{{ snowplow_utils.get_optional_fields(
enabled=var('snowplow__enable_screen_context', false),
col_prefix='contexts_com_snowplowanalytics_mobile_screen_1_',
fields=screen_context_fields(),
relation=source('atomic','events'),
relation_alias='a') }},
-- mobile context
{{ snowplow_utils.get_optional_fields(
enabled=var('snowplow__enable_mobile_context', false),
col_prefix='contexts_com_snowplowanalytics_snowplow_mobile_context_1_',
fields=mobile_context_fields(),
relation=source('atomic','events'),
relation_alias='a') }},
-- geo context
{{ snowplow_utils.get_optional_fields(
enabled=var('snowplow__enable_geolocation_context', false),
col_prefix='contexts_com_snowplowanalytics_snowplow_geolocation_context_1_',
fields=geo_context_fields(),
relation=source('atomic','events'),
relation_alias='a') }},
-- app context
{{ snowplow_utils.get_optional_fields(
enabled=var('snowplow__enable_application_context', false),
col_prefix='contexts_com_snowplowanalytics_mobile_application_1_',
fields=app_context_fields(),
relation=source('atomic','events'),
relation_alias='a') }},
-- session context
{{ snowplow_utils.get_optional_fields(
enabled=true,
col_prefix='contexts_com_snowplowanalytics_snowplow_client_session_1_',
fields=session_context_fields(),
relation=source('atomic','events'),
relation_alias='a') }},

a.*

from {{ var('snowplow__events') }} as a
inner join {{ ref('snowplow_mobile_base_sessions_this_run') }} as b
on {{ session_id }} = b.session_id

where a.collector_tstamp <= {{ snowplow_utils.timestamp_add('day', var("snowplow__max_session_days", 3), 'b.start_tstamp') }}
and a.dvce_sent_tstamp <= {{ snowplow_utils.timestamp_add('day', var("snowplow__days_late_allowed", 3), 'a.dvce_created_tstamp') }}
and a.collector_tstamp >= {{ lower_limit }}
and a.collector_tstamp <= {{ upper_limit }}
{% if var('snowplow__derived_tstamp_partitioned', true) and target.type == 'bigquery' | as_bool() %} -- BQ only
and a.derived_tstamp >= {{ snowplow_utils.timestamp_add('hour', -1, lower_limit) }}
and a.derived_tstamp <= {{ upper_limit }}
{% endif %}
and {{ snowplow_utils.app_id_filter(var("snowplow__app_id",[])) }}
and a.platform in ('{{ var("snowplow__platform")|join("','") }}') -- filters for 'mob' by default
)

, deduped_events as (
-- without downstream joins, it's safe to dedupe by picking the first event_id found.
select
array_agg(e order by e.collector_tstamp limit 1)[offset(0)].*

from events as e

group by e.event_id
)

select
d.*,
row_number() over(partition by d.session_id order by d.derived_tstamp) as event_index_in_session

from deduped_events as d

Depends On

Referenced By

Snowplow Mobile Base Events This Run Limitsโ€‹

models/base/scratch/<adaptor>/snowplow_mobile_base_events_this_run_limits.sql

Description

This table contains the lower and upper timestamp limits for the given run of the mobile model. These limits are used to select new events from the events table. These limits are determined by taking the MIN of the start_tstamp and MAX of the end_tstamp from the snowplow_mobile_base_sessions_this_run table for the lower_limit and upper_limit respectively.

File Paths

models/base/scratch/redshift_postgres/snowplow_mobile_base_events_this_run_limits.sql

Details

Columns
Column NameDescription
lower_limitThe min start_tstamp of all events processed this run
upper_limitThe max end_tstamp of all events processed this run
Code
Source
select
min(s.start_tstamp) as lower_limit,
max(s.end_tstamp) as upper_limit

from {{ ref('snowplow_mobile_base_sessions_this_run') }} s

Snowplow Mobile Base Geo Contextโ€‹

models/base/scratch/<adaptor>/contexts/snowplow_mobile_base_geo_context.sql

Description

This table only exists when working in a Redshift or Postgres warehouse.

This optional table provides extra context on an event level and brings in data surrounding a device's geographical properties, such as latitude/longitude, altitude, and speed.

File Paths

models/base/scratch/redshift_postgres/contexts/snowplow_mobile_base_geo_context.sql

Details

Columns
Column NameDescription
root_idThe corresponding UUID used in the root table.
root_tstampThe timestamp for when this event was produced.
device_latitudeLatitude coordinates for device location.
device_longitudeLongitude coordinates for device location.
device_latitude_longitude_accuracyAccuracy of Latitude and Longitude coordinates for device location.
device_altitudeAltitude coordinates for device location.
device_altitude_accuracyAccuracy of device altitude coordinates.
device_bearingHorizontal angle between device and true north.
device_speedMobile device speed.
Code
Source
{{
config(
enabled=(var("snowplow__enable_geolocation_context", false)
and target.type in ['redshift','postgres'] | as_bool()),
dist='root_id',
sort='root_tstamp'
)
}}

{%- set lower_limit, upper_limit = snowplow_utils.return_limits_from_model(
ref('snowplow_mobile_base_events_this_run_limits'),
'lower_limit',
'upper_limit') %}
with base as (

select
gc.root_id,
gc.root_tstamp,
gc.latitude AS device_latitude,
gc.longitude AS device_longitude,
gc.latitude_longitude_accuracy AS device_latitude_longitude_accuracy,
gc.altitude AS device_altitude,
gc.altitude_accuracy AS device_altitude_accuracy,
gc.bearing AS device_bearing,
gc.speed AS device_speed,
row_number() over (partition by root_id order by root_tstamp) dedupe_index

from {{ var("snowplow__geolocation_context") }} gc

where gc.root_tstamp between {{ lower_limit }} and {{ upper_limit }}

)

select *

from base

where dedupe_index = 1

Depends On

Snowplow Mobile Base Mobile Contextโ€‹

models/base/scratch/<adaptor>/contexts/snowplow_mobile_base_mobile_context.sql

Description

This table only exists when working in a Redshift or Postgres warehouse.

This optional table provides extra context on an event level and brings in data surrounding a device's manufacturer, model, and carrier.

File Paths

models/base/scratch/redshift_postgres/contexts/snowplow_mobile_base_mobile_context.sql

Details

Columns
Column NameDescription
root_idThe corresponding UUID used in the root table.
root_tstampThe timestamp for when this event was produced.
device_manufacturerManufacturer name of the device eg. Apple.
device_modelModel of the mobile device.
os_typeType of OS running on the mobile device.
os_versionOperation system full version.
android_idfaIdentifier for Advertisers for Android devices.
apple_idfaIdentifier for Advertisers for Apple devices.
apple_idfvIdentifier for Vendors for Apple devices.
carrierCarrier serivce provider used within device.
open_idfaIdentifier for Vendors for Open devices.
network_technologytechnology used by the network provider of the device.
network_typeType of network eg. 3G.
Code
Source
{{
config(
enabled=(var("snowplow__enable_mobile_context", false)
and target.type in ['redshift','postgres'] | as_bool()),
dist='root_id',
sort='root_tstamp'
)
}}

{%- set lower_limit, upper_limit = snowplow_utils.return_limits_from_model(
ref('snowplow_mobile_base_events_this_run_limits'),
'lower_limit',
'upper_limit') %}
with base as (

select
m.root_id,
m.root_tstamp,
m.device_manufacturer,
m.device_model,
m.os_type,
m.os_version,
m.android_idfa,
m.apple_idfa,
m.apple_idfv,
m.carrier,
m.open_idfa,
m.network_technology,
m.network_type,
row_number() over (partition by root_id order by root_tstamp) dedupe_index

from {{ var("snowplow__mobile_context") }} m

where m.root_tstamp between {{ lower_limit }} and {{ upper_limit }}

)

select *

from base

where dedupe_index = 1

Depends On

Snowplow Mobile Base New Event Limitsโ€‹

models/base/scratch/snowplow_mobile_base_new_event_limits.sql

Description

This table contains the lower and upper timestamp limits for the given run of the mobile model. These limits are used to select new events from the events table.

The sql to determine the correct limits for the run is generated by the get_run_limits() macro. Please refer to the documentation for details on how this macro determines the run limits.

Type: Table

Details

Columns
Column NameDescriptionType
lower_limitThe lower collector_tstamp limit for the runtimestamp_ntz
upper_limitThe upper collector_tstamp limit for the runtimestamp_ntz
Code
Source
{{ config(
post_hook=["{{snowplow_utils.print_run_limits(this)}}"],
sql_header=snowplow_utils.set_query_tag(var('snowplow__query_tag', 'snowplow_dbt'))
)
}}


{%- set models_in_run = snowplow_utils.get_enabled_snowplow_models('snowplow_mobile') -%}

{% set min_last_success,
max_last_success,
models_matched_from_manifest,
has_matched_all_models = snowplow_utils.get_incremental_manifest_status(ref('snowplow_mobile_incremental_manifest'),
models_in_run) -%}


{% set run_limits_query = snowplow_utils.get_run_limits(min_last_success,
max_last_success,
models_matched_from_manifest,
has_matched_all_models,
var("snowplow__start_date","2020-01-01")) -%}


{{ run_limits_query }}

Depends On

Referenced By

Snowplow Mobile Base Screen Contextโ€‹

models/base/scratch/<adaptor>/contexts/snowplow_mobile_base_screen_context.sql

Description

This table only exists when working in a Redshift or Postgres warehouse.

This optional table provides extra context on an event level and brings in data surrounding the screen that the application is on, such as the screen's id, activity, and type.

File Paths

models/base/scratch/redshift_postgres/contexts/snowplow_mobile_base_screen_context.sql

Details

Columns
Column NameDescription
root_idThe corresponding UUID used in the root table.
root_tstampThe timestamp for when this event was produced.
screen_idA UUID for each screen e.g. 738f1fbc-5298-46fa-9474-bc0a65f014ab.
screen_nameThe name set for a specific screen, e.g. DemoScreenName.
screen_activityThe name of the Activity element in the screen.
screen_fragmentThe name of the screen fragment (also known as an anchor).
screen_top_view_controllerThe name of the root view controller.
screen_typeThe type of screen that was viewed.
screen_view_controllerThe name of the view controller.
Code
Source
{{
config(
enabled=(var("snowplow__enable_screen_context", false)
and target.type in ['redshift','postgres'] | as_bool()),
dist='root_id',
sort='root_tstamp'
)
}}

{%- set lower_limit, upper_limit = snowplow_utils.return_limits_from_model(
ref('snowplow_mobile_base_events_this_run_limits'),
'lower_limit',
'upper_limit') %}

with base as (

select
sc.root_id,
sc.root_tstamp,
sc.id AS screen_id,
sc.name AS screen_name,
sc.activity AS screen_activity,
sc.fragment AS screen_fragment,
sc.top_view_controller AS screen_top_view_controller,
sc.type AS screen_type,
sc.view_controller AS screen_view_controller,
row_number() over (partition by root_id order by root_tstamp) dedupe_index

from {{ var("snowplow__screen_context") }} sc

where sc.root_tstamp between {{ lower_limit }} and {{ upper_limit }}

)

select *

from base

where dedupe_index = 1

Depends On

Snowplow Mobile Base Session Contextโ€‹

models/base/scratch/<adaptor>/contexts/snowplow_mobile_base_session_context.sql

Description

This table only exists when working in a Redshift or Postgres warehouse.

This optional table provides extra context on an event level and brings in data surrounding the session that the application is in, such as the session's first event ID, and the ID of the previous session.

File Paths

models/base/scratch/redshift_postgres/contexts/snowplow_mobile_base_session_context.sql

Details

Columns
Column NameDescription
root_idThe corresponding UUID used in the root table.
root_tstampThe timestamp for when this event was produced.
session_idA visit / session UUID e.g. c6ef3124-b53a-4b13-a233-0088f79dcbcb.
session_indexA visit / session index e.g. 3.
previous_session_idA previous visit / session index e.g. 3.
device_user_idUnique device user id.
session_first_event_idA first visit / session index e.g. 3.
Code
Source
{{
config(
enabled=(target.type in ['redshift','postgres'] | as_bool()),
dist='root_id',
sort='root_tstamp'
)
}}

{%- set lower_limit, upper_limit = snowplow_utils.return_limits_from_model(
ref('snowplow_mobile_base_events_this_run_limits'),
'lower_limit',
'upper_limit') %}
with base as (

select
s.root_id,
s.root_tstamp,
s.session_id,
s.session_index,
s.previous_session_id,
s.user_id as device_user_id,
s.first_event_id as session_first_event_id,
row_number() over (partition by root_id order by root_tstamp) dedupe_index

from {{ var("snowplow__session_context") }} s

where s.root_tstamp between {{ lower_limit }} and {{ upper_limit }}

)

select *

from base

where dedupe_index = 1

Depends On

Snowplow Mobile Base Sessions Lifecycle Manifestโ€‹

models/base/manifest/<adaptor>/snowplow_mobile_base_sessions_lifecycle_manifest.sql

Description

This incremental table is a manifest of all sessions that have been processed by the Snowplow dbt mobile model. For each session, the start and end timestamp is recorded.

By knowing the life-cycle of a session the model is able to able to determine which sessions and thus events to process for a given time-frame, as well as the complete date range required to reprocess all events of each session.

Type: Table

File Paths

models/base/manifest/default/snowplow_mobile_base_sessions_lifecycle_manifest.sql

Details

Columns
Column NameDescriptionType
session_idA visit / session UUID e.g. c6ef3124-b53a-4b13-a233-0088f79dcbcb.text
device_user_idUnique device user id.text
start_tstampThe collector_tstamp when the session began.timestamp_ntz
end_tstampThe collector_tstamp when the session ended.timestamp_ntz
Code
Source
{{
config(
materialized="incremental",
unique_key='session_id',
upsert_date_key='start_tstamp',
partition_by = snowplow_utils.get_value_by_target_type(bigquery_val={
"field": "start_tstamp",
"data_type": "timestamp"
}, databricks_val='start_tstamp_date'),
cluster_by=mobile_cluster_by_fields_sessions_lifecycle(),
full_refresh=snowplow_mobile.allow_refresh(),
tags=["manifest"],
sql_header=snowplow_utils.set_query_tag(var('snowplow__query_tag', 'snowplow_dbt')),
tblproperties={
'delta.autoOptimize.optimizeWrite' : 'true',
'delta.autoOptimize.autoCompact' : 'true'
},
snowplow_optimize=true
)
}}

{% set lower_limit, upper_limit, _ = snowplow_utils.return_base_new_event_limits(ref('snowplow_mobile_base_new_event_limits')) %}
{% set session_lookback_limit = snowplow_utils.get_session_lookback_limit(lower_limit) %}
{% set is_run_with_new_events = snowplow_utils.is_run_with_new_events('snowplow_mobile') %}
{% set session_id = snowplow_mobile.get_session_id_path_sql(relation_alias='e') %}
{% set user_id = snowplow_mobile.get_device_user_id_path_sql(relation_alias='e')%}

with new_events_session_ids as (
select
{{ session_id }} as session_id,
max( {{ user_id }} ) as device_user_id,
min(e.collector_tstamp) as start_tstamp,
max(e.collector_tstamp) as end_tstamp

from {{ var('snowplow__events') }} e

where
{{ session_id }} is not null
and e.dvce_sent_tstamp <= {{ snowplow_utils.timestamp_add('day', var("snowplow__days_late_allowed", 3), 'dvce_created_tstamp') }} -- don't process data that's too late
and e.collector_tstamp >= {{ lower_limit }}
and e.collector_tstamp <= {{ upper_limit }}
and {{ snowplow_utils.app_id_filter(var("snowplow__app_id",[])) }}
and e.platform in ('{{ var("snowplow__platform")|join("','") }}') -- filters for 'mob' by default
and {{ is_run_with_new_events }} --don't reprocess sessions that have already been processed.
{% if var('snowplow__derived_tstamp_partitioned', true) and target.type == 'bigquery' | as_bool() %} -- BQ only
and e.derived_tstamp >= {{ snowplow_utils.timestamp_add('hour', -1, lower_limit) }}
and e.derived_tstamp <= {{ upper_limit }}
{% endif %}
group by 1
)

{% if snowplow_utils.snowplow_is_incremental() %}

, previous_sessions as (
select *

from {{ this }}

where start_tstamp >= {{ session_lookback_limit }}
and {{ is_run_with_new_events }} --don't reprocess sessions that have already been processed.
)

, session_lifecycle as (
select
ns.session_id,
ns.device_user_id,
least(ns.start_tstamp, coalesce(self.start_tstamp, ns.start_tstamp)) as start_tstamp,
greatest(ns.end_tstamp, coalesce(self.end_tstamp, ns.end_tstamp)) as end_tstamp -- BQ 1 NULL will return null hence coalesce

from new_events_session_ids ns
left join previous_sessions as self
on ns.session_id = self.session_id

where
self.session_id is null -- process all new sessions
or self.end_tstamp < {{ snowplow_utils.timestamp_add('day', var("snowplow__max_session_days", 3), 'self.start_tstamp') }} --stop updating sessions exceeding 3 days
)

{% else %}

, session_lifecycle as (

select * from new_events_session_ids

)

{% endif %}

select
sl.session_id,
sl.device_user_id,
sl.start_tstamp,
least({{ snowplow_utils.timestamp_add('day', var("snowplow__max_session_days", 3), 'sl.start_tstamp') }}, sl.end_tstamp) as end_tstamp -- limit session length to max_session_days
{% if target.type in ['databricks', 'spark'] -%}
, DATE(start_tstamp) as start_tstamp_date
{%- endif %}

from session_lifecycle sl

Depends On

Referenced By

Snowplow Mobile Base Sessions This Runโ€‹

models/base/scratch/snowplow_mobile_base_sessions_this_run.sql

Description

For any given run, this table contains all the required sessions.

Type: Table

Details

Columns
Column NameDescriptionType
session_idA visit / session UUID e.g. c6ef3124-b53a-4b13-a233-0088f79dcbcb.text
device_user_idUnique device user id.text
start_tstampThe collector_tstamp when the session began.timestamp_ntz
end_tstampThe collector_tstamp when the session ended.timestamp_ntz
Code
Source
{{
config(
sort='start_tstamp',
dist='session_id',
tags=["this_run"],
sql_header=snowplow_utils.set_query_tag(var('snowplow__query_tag', 'snowplow_dbt'))
)
}}

{%- set lower_limit,
upper_limit,
session_start_limit = snowplow_utils.return_base_new_event_limits(ref('snowplow_mobile_base_new_event_limits')) %}

select
s.session_id,
s.device_user_id,
s.start_tstamp,
-- end_tstamp used in next step to limit events. When backfilling, set end_tstamp to upper_limit if end_tstamp > upper_limit.
-- This ensures we don't accidentally process events after upper_limit
case when s.end_tstamp > {{ upper_limit }} then {{ upper_limit }} else s.end_tstamp end as end_tstamp

from {{ ref('snowplow_mobile_base_sessions_lifecycle_manifest')}} s

where
-- General window of start_tstamps to limit table scans. Logic complicated by backfills.
-- To be within the run, session start_tstamp must be >= lower_limit - max_session_days as we limit end_tstamp in manifest to start_tstamp + max_session_days
s.start_tstamp >= {{ session_start_limit }}
and s.start_tstamp <= {{ upper_limit }}
-- Select sessions within window that either; start or finish between lower & upper limit, start and finish outside of lower and upper limits
and not (s.start_tstamp > {{ upper_limit }} or s.end_tstamp < {{ lower_limit }})

Depends On

Referenced By

Snowplow Mobile Incremental Manifestโ€‹

models/base/manifest/snowplow_mobile_incremental_manifest.sql

Description

This incremental table is a manifest of the timestamp of the latest event consumed per model within the snowplow-mobile package as well as any models leveraging the incremental framework provided by the package. The latest event's timestamp is based off collector_tstamp. This table is used to determine what events should be processed in the next run of the model.

Type: Table

Details

Columns
Column NameDescriptionType
modelThe name of the model.text
last_successThe latest event consumed by the model, based on collector_tstamptimestamp_ntz
Code
Source
{{
config(
materialized='incremental',
full_refresh=snowplow_mobile.allow_refresh(),
sql_header=snowplow_utils.set_query_tag(var('snowplow__query_tag', 'snowplow_dbt')),
tblproperties={
'delta.autoOptimize.optimizeWrite' : 'true',
'delta.autoOptimize.autoCompact' : 'true'
}
)
}}

-- Boilerplate to generate table.
-- Table updated as part of end-run hook

with prep as (
select
cast(null as {{ snowplow_utils.type_max_string() }}) model,
cast('1970-01-01' as {{ type_timestamp() }}) as last_success
)

select *

from prep
where false

Depends On

Referenced By

Snowplow Mobile Screen Viewsโ€‹

models/screen_views/snowplow_mobile_screen_views.sql

Description

This staging table contains all the screen views for the given run of the mobile model. It possess all the same columns as snowplow_mobile_screen_views. If building a custom module that requires screen view events, this is the table you should reference.

Type: Table

Details

Columns
Column NameDescriptionType
screen_view_idThe UUID of a screen view.text
event_idA UUID for each event e.g. c6ef3124-b53a-4b13-a233-0088f79dcbcb.text
app_idApplication ID e.g. angry-birds is used to distinguish different applications that are being tracked by the same Snowplow stack, e.g. production versus dev.text
user_idUnique ID set by business e.g. jon.doe@email.com.text
device_user_idUnique device user id.text
network_useridUser ID set by Snowplow using 3rd party cookie e.g. ecdff4d0-9175-40ac-a8bb-325c49733607.text
session_idA visit / session UUID e.g. c6ef3124-b53a-4b13-a233-0088f79dcbcb.text
session_indexA visit / session index e.g. 3.number
previous_session_idA previous visit / session index e.g. 3.text
session_first_event_idA first visit / session index e.g. 3.text
screen_view_in_session_indexThe index of the screen view within the session. This is generated by the tracker.number
screen_views_in_sessionTotal number of screen views within a session.number
dvce_created_tstampTimestamp event was recorded on the client device e.g. 2013-11-26 00:03:57.885.timestamp_ntz
collector_tstampTime stamp for the event recorded by the collector e.g. 2013-11-26 00:02:05.timestamp_ntz
derived_tstampTimestamp making allowance for innaccurate device clock e.g. 2013-11-26 00:02:04.timestamp_ntz
model_tstampThe current timestamp when the model processed this row.timestamp_ntz
screen_view_nameName of the screen viewed.text
screen_view_transition_typeThe type of transition that led to the screen being viewed.text
screen_view_typeThe type of screen that was viewed.text
screen_fragmentThe name of the screen fragment (also known as an anchor).text
screen_top_view_controllerThe name of the root view controller.text
screen_view_controllerThe name of the view controller.text
screen_view_previous_idThe UUID of the previous screen view.text
screen_view_previous_nameThe name of the previous screen view.text
screen_view_previous_typeThe type of the previous screen viewed.text
platformPlatform e.g. web.text
dvce_screenwidthScreen width in pixels e.g. 1900.number
dvce_screenheightScreen height in pixels e.g. 1024.number
device_manufacturerManufacturer name of the device eg. Apple.text
device_modelModel of the mobile device.text
os_typeType of OS running on the mobile device.text
os_versionOperation system full version.text
android_idfaIdentifier for Advertisers for Android devices.text
apple_idfaIdentifier for Advertisers for Apple devices.text
apple_idfvIdentifier for Vendors for Apple devices.text
open_idfaIdentifier for Vendors for Open devices.text
device_latitudeLatitude coordinates for device location.float
device_longitudeLongitude coordinates for device location.float
device_latitude_longitude_accuracyAccuracy of Latitude and Longitude coordinates for device location.float
device_altitudeAltitude coordinates for device location.float
device_altitude_accuracyAccuracy of device altitude coordinates.float
device_bearingHorizontal angle between device and true north.float
device_speedMobile device speed.float
geo_countryISO 3166-1 code for the country the visitor is located in e.g. GB, US.text
geo_regionISO-3166-2 code for country region the visitor is in e.g. I9, TX.text
geo_cityCity the visitor is in e.g. New York, London.text
geo_zipcodePostcode the visitor is in e.g. 94109.text
geo_latitudeVisitor location latitude e.g. 37.443604.float
geo_longitudeVisitor location longitude e.g. -122.4124.float
geo_region_nameVisitor region name e.g. Florida.text
geo_timezoneVisitor timezone name e.g. Europe/London.text
user_ipaddressUser IP address e.g. 92.231.54.234.text
useragentRaw useragent.text
carrierCarrier serivce provider used within device.text
network_technologytechnology used by the network provider of the device.text
network_typeType of network eg. 3G.text
buildThe build of the application.text
versionThe application version.text
Code
Source
{{
config(
materialized="incremental",
unique_key='screen_view_id',
upsert_date_key='derived_tstamp',
sort='derived_tstamp',
dist='screen_view_id',
partition_by = snowplow_utils.get_value_by_target_type(bigquery_val={
"field": "derived_tstamp",
"data_type": "timestamp"
}, databricks_val='derived_tstamp_date'),
cluster_by=snowplow_mobile.mobile_cluster_by_fields_screen_views(),
tags=["derived"],
sql_header=snowplow_utils.set_query_tag(var('snowplow__query_tag', 'snowplow_dbt')),
tblproperties={
'delta.autoOptimize.optimizeWrite' : 'true',
'delta.autoOptimize.autoCompact' : 'true'
},
snowplow_optimize=true
)
}}


select *
{% if target.type in ['databricks', 'spark'] -%}
, DATE(derived_tstamp) as derived_tstamp_date
{%- endif %}
from {{ ref('snowplow_mobile_screen_views_this_run') }}
where {{ snowplow_utils.is_run_with_new_events('snowplow_mobile') }} --returns false if run doesn't contain new events.

Depends On

Snowplow Mobile Screen Views This Runโ€‹

models/screen_views/scratch/<adaptor>/snowplow_mobile_screen_views_this_run.sql

Description

This staging table contains all the screen views for the given run of the mobile model. It possess all the same columns as snowplow_mobile_screen_views. If building a custom module that requires screen view events, this is the table you should reference.

Type: Table

File Paths

models/screen_views/scratch/default/snowplow_mobile_screen_views_this_run.sql

Details

Columns
Column NameDescriptionType
screen_view_idThe UUID of a screen view.text
event_idA UUID for each event e.g. c6ef3124-b53a-4b13-a233-0088f79dcbcb.text
app_idApplication ID e.g. angry-birds is used to distinguish different applications that are being tracked by the same Snowplow stack, e.g. production versus dev.text
user_idUnique ID set by business e.g. jon.doe@email.com.text
device_user_idUnique device user id.text
network_useridUser ID set by Snowplow using 3rd party cookie e.g. ecdff4d0-9175-40ac-a8bb-325c49733607.text
session_idA visit / session UUID e.g. c6ef3124-b53a-4b13-a233-0088f79dcbcb.text
session_indexA visit / session index e.g. 3.number
previous_session_idA previous visit / session index e.g. 3.text
session_first_event_idA first visit / session index e.g. 3.text
screen_view_in_session_indexThe index of the screen view within the session. This is generated by the tracker.number
screen_views_in_sessionTotal number of screen views within a session.number
dvce_created_tstampTimestamp event was recorded on the client device e.g. 2013-11-26 00:03:57.885.timestamp_ntz
collector_tstampTime stamp for the event recorded by the collector e.g. 2013-11-26 00:02:05.timestamp_ntz
derived_tstampTimestamp making allowance for innaccurate device clock e.g. 2013-11-26 00:02:04.timestamp_ntz
model_tstampThe current timestamp when the model processed this row.timestamp_ntz
screen_view_nameName of the screen viewed.text
screen_view_transition_typeThe type of transition that led to the screen being viewed.text
screen_view_typeThe type of screen that was viewed.text
screen_fragmentThe name of the screen fragment (also known as an anchor).text
screen_top_view_controllerThe name of the root view controller.text
screen_view_controllerThe name of the view controller.text
screen_view_previous_idThe UUID of the previous screen view.text
screen_view_previous_nameThe name of the previous screen view.text
screen_view_previous_typeThe type of the previous screen viewed.text
platformPlatform e.g. web.text
dvce_screenwidthScreen width in pixels e.g. 1900.number
dvce_screenheightScreen height in pixels e.g. 1024.number
device_manufacturerManufacturer name of the device eg. Apple.text
device_modelModel of the mobile device.text
os_typeType of OS running on the mobile device.text
os_versionOperation system full version.text
android_idfaIdentifier for Advertisers for Android devices.text
apple_idfaIdentifier for Advertisers for Apple devices.text
apple_idfvIdentifier for Vendors for Apple devices.text
open_idfaIdentifier for Vendors for Open devices.text
device_latitudeLatitude coordinates for device location.float
device_longitudeLongitude coordinates for device location.float
device_latitude_longitude_accuracyAccuracy of Latitude and Longitude coordinates for device location.float
device_altitudeAltitude coordinates for device location.float
device_altitude_accuracyAccuracy of device altitude coordinates.float
device_bearingHorizontal angle between device and true north.float
device_speedMobile device speed.float
geo_countryISO 3166-1 code for the country the visitor is located in e.g. GB, US.text
geo_regionISO-3166-2 code for country region the visitor is in e.g. I9, TX.text
geo_cityCity the visitor is in e.g. New York, London.text
geo_zipcodePostcode the visitor is in e.g. 94109.text
geo_latitudeVisitor location latitude e.g. 37.443604.float
geo_longitudeVisitor location longitude e.g. -122.4124.float
geo_region_nameVisitor region name e.g. Florida.text
geo_timezoneVisitor timezone name e.g. Europe/London.text
user_ipaddressUser IP address e.g. 92.231.54.234.text
useragentRaw useragent.text
carrierCarrier serivce provider used within device.text
network_technologytechnology used by the network provider of the device.text
network_typeType of network eg. 3G.text
buildThe build of the application.text
versionThe application version.text
Code
Source
{{
config(
cluster_by=snowplow_utils.get_value_by_target_type(bigquery_val=["session_id"]),
tags=["this_run"],
sql_header=snowplow_utils.set_query_tag(var('snowplow__query_tag', 'snowplow_dbt'))
)
}}

with screen_views_dedupe as (
select
ev.screen_view_id,
ev.event_id,

ev.app_id,

ev.user_id,
ev.device_user_id,
ev.network_userid,

ev.session_id,
ev.session_index,
ev.previous_session_id,
ev.session_first_event_id,

ev.dvce_created_tstamp,
ev.collector_tstamp,
ev.derived_tstamp,

ev.screen_view_name,
ev.screen_view_transition_type,
ev.screen_view_type,
ev.screen_fragment,
ev.screen_top_view_controller,
ev.screen_view_controller,
ev.screen_view_previous_id,
ev.screen_view_previous_name,
ev.screen_view_previous_type,

ev.platform,
ev.dvce_screenwidth,
ev.dvce_screenheight,
ev.device_manufacturer,
ev.device_model,
ev.os_type,
ev.os_version,
ev.android_idfa,
ev.apple_idfa,
ev.apple_idfv,

ev.device_latitude,
ev.device_longitude,
ev.device_latitude_longitude_accuracy,
ev.device_altitude,
ev.device_altitude_accuracy,
ev.device_bearing,
ev.device_speed,
ev.geo_country,
ev.geo_region,
ev.geo_city,
ev.geo_zipcode,
ev.geo_latitude,
ev.geo_longitude,
ev.geo_region_name,
ev.geo_timezone,

ev.user_ipaddress,

ev.useragent,

ev.carrier,
ev.open_idfa,
ev.network_technology,
ev.network_type,

ev.build,
ev.version,

row_number() over (partition by ev.screen_view_id order by ev.derived_tstamp) as screen_view_id_index

from {{ ref('snowplow_mobile_base_events_this_run') }} as ev

where ev.event_name = 'screen_view'
and ev.screen_view_id is not null
)

, cleaned_screen_view_events AS (
select
*,
row_number() over (partition by sv.session_id order by sv.derived_tstamp) as screen_view_in_session_index

from screen_views_dedupe sv

where sv.screen_view_id_index = 1 --take first row of duplicates
)

select
ev.screen_view_id,
ev.event_id,

ev.app_id,

ev.user_id,
ev.device_user_id,
ev.network_userid,

ev.session_id,
ev.session_index,
ev.previous_session_id,
ev.session_first_event_id,

ev.screen_view_in_session_index,
max(ev.screen_view_in_session_index) over (partition by ev.session_id) as screen_views_in_session,

ev.dvce_created_tstamp,
ev.collector_tstamp,
ev.derived_tstamp,
{{ snowplow_utils.current_timestamp_in_utc() }} AS model_tstamp,

ev.screen_view_name,
ev.screen_view_transition_type,
ev.screen_view_type,
ev.screen_fragment,
ev.screen_top_view_controller,
ev.screen_view_controller,
ev.screen_view_previous_id,
ev.screen_view_previous_name,
ev.screen_view_previous_type,

ev.platform,
ev.dvce_screenwidth,
ev.dvce_screenheight,
ev.device_manufacturer,
ev.device_model,
ev.os_type,
ev.os_version,
ev.android_idfa,
ev.apple_idfa,
ev.apple_idfv,
ev.open_idfa,

ev.device_latitude,
ev.device_longitude,
ev.device_latitude_longitude_accuracy,
ev.device_altitude,
ev.device_altitude_accuracy,
ev.device_bearing,
ev.device_speed,
ev.geo_country,
ev.geo_region,
ev.geo_city,
ev.geo_zipcode,
ev.geo_latitude,
ev.geo_longitude,
ev.geo_region_name,
ev.geo_timezone,

ev.user_ipaddress,

ev.useragent,

ev.carrier,
ev.network_technology,
ev.network_type,

ev.build,
ev.version

from cleaned_screen_view_events ev

Depends On

Referenced By

Snowplow Mobile Sessionsโ€‹

models/sessions/snowplow_mobile_sessions.sql

Description

This derived incremental table contains all historic sessions and should be the end point for any analysis or BI tools.

Type: Table

Details

Columns
Column NameDescriptionType
app_idApplication ID e.g. angry-birds is used to distinguish different applications that are being tracked by the same Snowplow stack, e.g. production versus dev.text
session_idA visit / session UUID e.g. c6ef3124-b53a-4b13-a233-0088f79dcbcb.text
session_indexA visit / session index e.g. 3.number
previous_session_idA previous visit / session index e.g. 3.text
session_first_event_idA first visit / session index e.g. 3.text
session_last_event_idA last visit / session index e.g. 3.text
start_tstampTimestamp for the start of the session, based on derived_tstamp.timestamp_ntz
end_tstampTimestamp for the end of the session, based on derived_tstamp.timestamp_ntz
model_tstampThe current timestamp when the model processed this row.timestamp_ntz
user_idUnique ID set by business e.g. jon.doe@email.com.text
device_user_idUnique device user id.text
network_useridUser ID set by Snowplow using 3rd party cookie e.g. ecdff4d0-9175-40ac-a8bb-325c49733607.text
stitched_user_idtext
session_duration_sTotal duration of a session in seconds.number
has_installYes/No whether application is installed or not.boolean
screen_viewsTotal number of screen views within a session.number
screen_names_viewedThe number of different screens viewed where the unique screens are counted by the screen names.number
app_errorsTotal number of app errors.number
fatal_app_errorsTotoal number of fatal app errors.number
first_event_nameName of the first event fired in the session.text
last_event_nameName of the last event fired in the session.text
first_screen_view_nameName of the first screen viewed.text
first_screen_view_transition_typeType of transition for the first screen view.text
first_screen_view_typeType of first screen view.text
last_screen_view_nameName of the last screen viewed.text
last_screen_view_transition_typeType of transition for the last screen view.text
last_screen_view_typeType of last screen view.text
platformPlatform e.g. web.text
dvce_screenwidthScreen width in pixels e.g. 1900.number
dvce_screenheightScreen height in pixels e.g. 1024.number
device_manufacturerManufacturer name of the device eg. Apple.text
device_modelModel of the mobile device.text
os_typeType of OS running on the mobile device.text
os_versionOperation system full version.text
android_idfaIdentifier for Advertisers for Android devices.text
apple_idfaIdentifier for Advertisers for Apple devices.text
apple_idfvIdentifier for Vendors for Apple devices.text
open_idfaIdentifier for Vendors for Open devices.text
device_latitudeLatitude coordinates for device location.float
device_longitudeLongitude coordinates for device location.float
device_latitude_longitude_accuracyAccuracy of Latitude and Longitude coordinates for device location.float
device_altitudeAltitude coordinates for device location.float
device_altitude_accuracyAccuracy of device altitude coordinates.float
device_bearingHorizontal angle between device and true north.float
device_speedMobile device speed.float
geo_countryISO 3166-1 code for the country the visitor is located in e.g. GB, US.text
geo_regionISO-3166-2 code for country region the visitor is in e.g. I9, TX.text
geo_cityCity the visitor is in e.g. New York, London.text
geo_zipcodePostcode the visitor is in e.g. 94109.text
geo_latitudeVisitor location latitude e.g. 37.443604.float
geo_longitudeVisitor location longitude e.g. -122.4124.float
geo_region_nameVisitor region name e.g. Florida.text
geo_timezoneVisitor timezone name e.g. Europe/London.text
user_ipaddressUser IP address e.g. 92.231.54.234.text
useragentRaw useragent.text
name_trackerTracker namespace e.g. sp1.text
v_trackerTracker version e.g. js-3.0.0.text
carrierCarrier serivce provider used within device.text
network_technologytechnology used by the network provider of the device.text
network_typeType of network eg. 3G.text
first_buildFirst build of the application.text
last_buildLast build of the application.text
first_versionFirst application version.text
last_versionLast application version.text
Code
Source
{{
config(
materialized="incremental",
unique_key='session_id',
upsert_date_key='start_tstamp',
sort='start_tstamp',
dist='session_id',
partition_by = snowplow_utils.get_value_by_target_type(bigquery_val={
"field": "start_tstamp",
"data_type": "timestamp"
}, databricks_val='start_tstamp_date'),
cluster_by=snowplow_mobile.mobile_cluster_by_fields_sessions(),
tags=["derived"],
post_hook="{{ snowplow_mobile.stitch_user_identifiers(
enabled=var('snowplow__session_stitching')
) }}",
sql_header=snowplow_utils.set_query_tag(var('snowplow__query_tag', 'snowplow_dbt')),
tblproperties={
'delta.autoOptimize.optimizeWrite' : 'true',
'delta.autoOptimize.autoCompact' : 'true'
},
snowplow_optimize=true
)
}}


select *
{% if target.type in ['databricks', 'spark'] -%}
, DATE(start_tstamp) as start_tstamp_date
{%- endif %}
from {{ ref('snowplow_mobile_sessions_this_run') }}
where {{ snowplow_utils.is_run_with_new_events('snowplow_mobile') }} --returns false if run doesn't contain new events.

Depends On

Referenced By

Snowplow Mobile Sessions Aggsโ€‹

models/sessions/scratch/snowplow_mobile_sessions_aggs.sql

Description

This model aggregates various metrics derived from page views to a session level.

Type: Table

Details

Columns
Column NameDescriptionType
session_idA visit / session UUID e.g. c6ef3124-b53a-4b13-a233-0088f79dcbcb.text
last_buildLast build of the application.text
last_versionLast application version.text
last_event_nameName of the last event fired in the session.text
session_last_event_idA last visit / session index e.g. 3.text
start_tstampTimestamp for the end of the session, based on derived_tstamp.timestamp_ntz
end_tstampTimestamp for the end of the session, based on derived_tstamp.timestamp_ntz
session_duration_sTotal duration of a session in seconds.number
has_installYes/No whether application is installed or not.boolean
app_errorsTotal number of app errors.number
fatal_app_errorsTotoal number of fatal app errors.number
Code
Source
{{
config(
partition_by = snowplow_utils.get_value_by_target_type(bigquery_val={
"field": "start_tstamp",
"data_type": "timestamp"
}),
cluster_by=snowplow_utils.get_value_by_target_type(bigquery_val=["session_id"]),
sort='session_id',
dist='session_id',
sql_header=snowplow_utils.set_query_tag(var('snowplow__query_tag', 'snowplow_dbt'))
)
}}

with events as (
select
es.session_id,
es.event_id,
es.event_name,
es.derived_tstamp,
es.build,
es.version,
es.event_index_in_session,
MAX(es.event_index_in_session) over (partition by es.session_id) as events_in_session

from {{ ref('snowplow_mobile_base_events_this_run') }} es
)

, session_aggs AS (
select
e.session_id,
--last dimensions
MAX(case when e.event_index_in_session = e.events_in_session then e.build end) as last_build,
MAX(case when e.event_index_in_session = e.events_in_session then e.version end) as last_version,
MAX(case when e.event_index_in_session = e.events_in_session then e.event_name end) as last_event_name,
{% if target.type == 'postgres' %}
cast(MAX(case when e.event_index_in_session = e.events_in_session then cast(e.event_id as {{ type_string() }}) end) as uuid) as session_last_event_id,
{% else %}
MAX(case when e.event_index_in_session = e.events_in_session then e.event_id end) as session_last_event_id,
{% endif %}

-- time
MIN(e.derived_tstamp) as start_tstamp,
MAX(e.derived_tstamp) as end_tstamp,
{{ snowplow_mobile.bool_or("e.event_name = 'application_install'") }} as has_install

from events e

group by 1
)

, app_errors as (
{% if var("snowplow__enable_app_errors_module", false) %}
select
ae.session_id,
COUNT(distinct ae.event_id) AS app_errors,
COUNT(distinct case when ae.is_fatal then ae.event_id end) as fatal_app_errors

from {{ ref('snowplow_mobile_app_errors_this_run') }} ae

group by 1
{% else %}
select
{% if target.type == 'postgres' %}
cast(null as uuid) as session_id,
{% else %}
cast(null as {{type_string() }}) as session_id,
{% endif %}
cast(null as {{ type_int() }}) as app_errors,
cast(null as {{ type_int() }}) as fatal_app_errors
{% endif %}
)


select
sa.session_id,
sa.last_build,
sa.last_version,
sa.last_event_name,
sa.session_last_event_id,
sa.start_tstamp,
sa.end_tstamp,
{{ snowplow_utils.timestamp_diff('sa.start_tstamp', 'sa.end_tstamp', 'second') }} as session_duration_s,
sa.has_install,
ae.app_errors,
ae.fatal_app_errors

from session_aggs sa
left join app_errors ae
on sa.session_id = ae.session_id

Depends On

Referenced By

Snowplow Mobile Sessions Sv Detailsโ€‹

models/sessions/scratch/snowplow_mobile_sessions_sv_details.sql

Description

This model identifies the last page view within a given session and returns various dimensions associated with that page view.

Type: Table

Details

Columns
Column NameDescriptionType
session_idA visit / session UUID e.g. c6ef3124-b53a-4b13-a233-0088f79dcbcb.text
screen_viewsTotal number of screen views within a session.number
screen_names_viewedThe number of different screens viewed where the unique screens are counted by the screen names.number
first_screen_view_nameName of the first screen viewed.text
first_screen_view_transition_typeType of transition for the first screen view.text
first_screen_view_typeType of first screen view.text
last_screen_view_nameName of the last screen viewed.text
last_screen_view_transition_typeType of transition for the last screen view.text
last_screen_view_typeType of last screen view.text
Code
Source
{{
config(
cluster_by=snowplow_utils.get_value_by_target_type(bigquery_val=["session_id"]),
sort='session_id',
dist='session_id',
sql_header=snowplow_utils.set_query_tag(var('snowplow__query_tag', 'snowplow_dbt'))
)
}}

select
sv.session_id,
COUNT(distinct sv.screen_view_id) as screen_views,
COUNT(distinct sv.screen_view_name) as screen_names_viewed,
--Could split below into first/last scratch tables. Trying to minimise joins to sessions.
MAX(case when sv.screen_view_in_session_index = 1 then sv.screen_view_name end) as first_screen_view_name,
MAX(case when sv.screen_view_in_session_index = 1 then sv.screen_view_transition_type end) as first_screen_view_transition_type,
MAX(case when sv.screen_view_in_session_index = 1 then sv.screen_view_type end) as first_screen_view_type,
MAX(case when sv.screen_view_in_session_index = sv.screen_views_in_session then sv.screen_view_name end) as last_screen_view_name,
MAX(case when sv.screen_view_in_session_index = sv.screen_views_in_session then sv.screen_view_transition_type end) as last_screen_view_transition_type,
MAX(case when sv.screen_view_in_session_index = sv.screen_views_in_session then sv.screen_view_type end) as last_screen_view_type

from {{ ref('snowplow_mobile_screen_views_this_run') }} sv

group by 1

Depends On

Referenced By

Snowplow Mobile Sessions This Runโ€‹

models/sessions/scratch/snowplow_mobile_sessions_this_run.sql

Description

This staging table contains all the sessions for the given run of the Mob model. It possess all the same columns as snowplow_mobile_sessions. If building a custom module that requires session level data, this is the table you should reference.

Type: Table

Details

Columns
Column NameDescriptionType
app_idApplication ID e.g. angry-birds is used to distinguish different applications that are being tracked by the same Snowplow stack, e.g. production versus dev.text
session_idA visit / session UUID e.g. c6ef3124-b53a-4b13-a233-0088f79dcbcb.text
session_indexA visit / session index e.g. 3.number
previous_session_idA previous visit / session index e.g. 3.text
session_first_event_idA first visit / session index e.g. 3.text
session_last_event_idA last visit / session index e.g. 3.text
start_tstampTimestamp for the start of the session, based on derived_tstamp.timestamp_ntz
end_tstampTimestamp for the end of the session, based on derived_tstamp.timestamp_ntz
model_tstampThe current timestamp when the model processed this row.timestamp_ntz
user_idUnique ID set by business e.g. jon.doe@email.com.text
device_user_idUnique device user id.text
network_useridUser ID set by Snowplow using 3rd party cookie e.g. ecdff4d0-9175-40ac-a8bb-325c49733607.text
stitched_user_idtext
session_duration_sTotal duration of a session in seconds.number
has_installYes/No whether application is installed or not.boolean
screen_viewsTotal number of screen views within a session.number
screen_names_viewedThe number of different screens viewed where the unique screens are counted by the screen names.number
app_errorsTotal number of app errors.number
fatal_app_errorsTotoal number of fatal app errors.number
first_event_nameName of the first event fired in the session.text
last_event_nameName of the last event fired in the session.text
first_screen_view_nameName of the first screen viewed.text
first_screen_view_transition_typeType of transition for the first screen view.text
first_screen_view_typeType of first screen view.text
last_screen_view_nameName of the last screen viewed.text
last_screen_view_transition_typeType of transition for the last screen view.text
last_screen_view_typeType of last screen view.text
platformPlatform e.g. web.text
dvce_screenwidthScreen width in pixels e.g. 1900.number
dvce_screenheightScreen height in pixels e.g. 1024.number
device_manufacturerManufacturer name of the device eg. Apple.text
device_modelModel of the mobile device.text
os_typeType of OS running on the mobile device.text
os_versionOperation system full version.text
android_idfaIdentifier for Advertisers for Android devices.text
apple_idfaIdentifier for Advertisers for Apple devices.text
apple_idfvIdentifier for Vendors for Apple devices.text
open_idfaIdentifier for Vendors for Open devices.text
device_latitudeLatitude coordinates for device location.float
device_longitudeLongitude coordinates for device location.float
device_latitude_longitude_accuracyAccuracy of Latitude and Longitude coordinates for device location.float
device_altitudeAltitude coordinates for device location.float
device_altitude_accuracyAccuracy of device altitude coordinates.float
device_bearingHorizontal angle between device and true north.float
device_speedMobile device speed.float
geo_countryISO 3166-1 code for the country the visitor is located in e.g. GB, US.text
geo_regionISO-3166-2 code for country region the visitor is in e.g. I9, TX.text
geo_cityCity the visitor is in e.g. New York, London.text
geo_zipcodePostcode the visitor is in e.g. 94109.text
geo_latitudeVisitor location latitude e.g. 37.443604.float
geo_longitudeVisitor location longitude e.g. -122.4124.float
geo_region_nameVisitor region name e.g. Florida.text
geo_timezoneVisitor timezone name e.g. Europe/London.text
user_ipaddressUser IP address e.g. 92.231.54.234.text
useragentRaw useragent.text
name_trackerTracker namespace e.g. sp1.text
v_trackerTracker version e.g. js-3.0.0.text
carrierCarrier serivce provider used within device.text
network_technologytechnology used by the network provider of the device.text
network_typeType of network eg. 3G.text
first_buildFirst build of the application.text
last_buildLast build of the application.text
first_versionFirst application version.text
last_versionLast application version.text
Code
Source
{{
config(
sort='start_tstamp',
dist='session_id',
tags=["this_run"],
sql_header=snowplow_utils.set_query_tag(var('snowplow__query_tag', 'snowplow_dbt'))
)
}}

select
-- app id
es.app_id,

-- session fields
es.session_id,
es.session_index,
es.previous_session_id,
es.session_first_event_id,
sa.session_last_event_id,

sa.start_tstamp,
sa.end_tstamp,
{{ snowplow_utils.current_timestamp_in_utc() }} as model_tstamp,

-- user fields
es.user_id,
es.device_user_id,
es.network_userid,

{% if var('snowplow__session_stitching') %}
-- updated with mapping as part of post hook on derived sessions table
cast(es.device_user_id as {{snowplow_utils.type_max_string() }}) as stitched_user_id,
{% else %}
cast(null as {{ snowplow_utils.type_max_string() }}) as stitched_user_id,
{% endif %}

sa.session_duration_s,
sa.has_install,
sv.screen_views,
sv.screen_names_viewed,
cast(sa.app_errors as {{ type_int() }}) as app_errors,
cast(sa.fatal_app_errors as {{ type_int() }}) as fatal_app_errors,

es.event_name as first_event_name,
sa.last_event_name,

sv.first_screen_view_name,
sv.first_screen_view_transition_type,
sv.first_screen_view_type,

sv.last_screen_view_name,
sv.last_screen_view_transition_type,
sv.last_screen_view_type,

es.platform,
es.dvce_screenwidth,
es.dvce_screenheight,
es.device_manufacturer,
es.device_model,
es.os_type,
es.os_version,
es.android_idfa,
es.apple_idfa,
es.apple_idfv,
es.open_idfa,

es.device_latitude,
es.device_longitude,
es.device_latitude_longitude_accuracy,
es.device_altitude,
es.device_altitude_accuracy,
es.device_bearing,
es.device_speed,
es.geo_country,
es.geo_region,
es.geo_city,
es.geo_zipcode,
es.geo_latitude,
es.geo_longitude,
es.geo_region_name,
es.geo_timezone,

es.user_ipaddress,

es.useragent,
es.name_tracker,
es.v_tracker,

es.carrier,
es.network_technology,
es.network_type,
--first/last build/version to measure app updates.
es.build as first_build,
sa.last_build,
es.version as first_version,
sa.last_version

from {{ ref('snowplow_mobile_base_events_this_run') }} as es

inner join {{ ref('snowplow_mobile_sessions_aggs') }} as sa
on es.session_id = sa.session_id
and es.event_index_in_session = 1

left join {{ ref('snowplow_mobile_sessions_sv_details') }} sv
on es.session_id = sv.session_id

Depends On

Referenced By

Snowplow Mobile User Mappingโ€‹

models/user_mapping/snowplow_mobile_user_mapping.sql

Description

A mapping table between device_user_id and user_id.

Type: Table

Details

Columns
Column NameDescriptionType
device_user_idUnique device user id.text
user_idUnique ID set by business e.g. jon.doe@email.com.text
end_tstampThe collector_tstamp when the user was last activetimestamp_ntz
Code
Source
{{
config(
materialized='incremental',
unique_key='device_user_id',
sort='end_tstamp',
dist='device_user_id',
partition_by = snowplow_utils.get_value_by_target_type(bigquery_val={
"field": "end_tstamp",
"data_type": "timestamp"
}),
tags=["derived"],
sql_header=snowplow_utils.set_query_tag(var('snowplow__query_tag', 'snowplow_dbt'))
)
}}


select distinct
device_user_id,
last_value(user_id) over(
partition by device_user_id
order by collector_tstamp
rows between unbounded preceding and unbounded following
) as user_id,
max(collector_tstamp) over (partition by device_user_id) as end_tstamp

from {{ ref('snowplow_mobile_base_events_this_run') }}

where {{ snowplow_utils.is_run_with_new_events('snowplow_mobile') }} --returns false if run doesn't contain new events.
and user_id is not null
and device_user_id is not null

Depends On

Referenced By

Snowplow Mobile Usersโ€‹

models/users/snowplow_mobile_users.sql

Description

This derived incremental table contains all historic users data and should be the end point for any analysis or BI tools.

Type: Table

Details

Columns
Column NameDescriptionType
user_idUnique ID set by business e.g. jon.doe@email.com.text
device_user_idUnique device user id.text
network_useridUser ID set by Snowplow using 3rd party cookie e.g. ecdff4d0-9175-40ac-a8bb-325c49733607.text
start_tstampEarliest timestamp for the user's activity, based on derived_tstamp.timestamp_ntz
end_tstampLatest timestamp for the user's activity, based on derived_tstamp.timestamp_ntz
model_tstampThe current timestamp when the model processed this row.timestamp_tz
screen_viewsTotal number of screen views within a session.number
screen_names_viewedThe number of different screens viewed where the unique screens are counted by the screen names.number
sessionsTotal number of session for the user.number
sessions_duration_sTotal session duration for the specific user.number
active_daysTotal number of active days for the user.number
app_errorsTotal number of app errors.number
fatal_app_errorsTotoal number of fatal app errors.number
first_screen_view_nameName of the first screen viewed.text
first_screen_view_transition_typeType of transition for the first screen view.text
first_screen_view_typeType of first screen view.text
last_screen_view_nameName of the last screen viewed.text
last_screen_view_transition_typeType of transition for the last screen view.text
last_screen_view_typeType of last screen view.text
platformPlatform e.g. web.text
dvce_screenwidthScreen width in pixels e.g. 1900.number
dvce_screenheightScreen height in pixels e.g. 1024.number
device_manufacturerManufacturer name of the device eg. Apple.text
device_modelModel of the mobile device.text
os_typeType of OS running on the mobile device.text
first_os_versionFirst Operating System version for user device.text
last_os_versionLast Operating System version for user device.text
android_idfaIdentifier for Advertisers for Android devices.text
apple_idfaIdentifier for Advertisers for Apple devices.text
apple_idfvIdentifier for Vendors for Apple devices.text
open_idfaIdentifier for Vendors for Open devices.text
geo_countryISO 3166-1 code for the country the visitor is located in e.g. GB, US.text
geo_regionISO-3166-2 code for country region the visitor is in e.g. I9, TX.text
geo_cityCity the visitor is in e.g. New York, London.text
geo_zipcodePostcode the visitor is in e.g. 94109.text
geo_latitudeVisitor location latitude e.g. 37.443604.float
geo_longitudeVisitor location longitude e.g. -122.4124.float
geo_region_nameVisitor region name e.g. Florida.text
geo_timezoneVisitor timezone name e.g. Europe/London.text
first_carrierFirst carrier for user.text
last_carrierLast carrier provider for user.text
Code
Source
{{
config(
materialized="incremental",
unique_key='device_user_id',
upsert_date_key='start_tstamp',
disable_upsert_lookback=true,
sort='start_tstamp',
dist='device_user_id',
partition_by = snowplow_utils.get_value_by_target_type(bigquery_val={
"field": "start_tstamp",
"data_type": "timestamp"
}, databricks_val='start_tstamp_date'),
cluster_by=snowplow_mobile.mobile_cluster_by_fields_users(),
tags=["derived"],
sql_header=snowplow_utils.set_query_tag(var('snowplow__query_tag', 'snowplow_dbt')),
tblproperties={
'delta.autoOptimize.optimizeWrite' : 'true',
'delta.autoOptimize.autoCompact' : 'true'
},
snowplow_optimize=true
)
}}

select *
{% if target.type in ['databricks', 'spark'] -%}
, DATE(start_tstamp) as start_tstamp_date
{%- endif %}
from {{ ref('snowplow_mobile_users_this_run') }}
where {{ snowplow_utils.is_run_with_new_events('snowplow_mobile') }} --returns false if run doesn't contain new events.

Depends On

Snowplow Mobile Users Aggsโ€‹

models/users/scratch/snowplow_mobile_users_aggs.sql

Description

This model aggregates various metrics derived from sessions to a users level.

Type: Table

Details

Columns
Column NameDescriptionType
device_user_idUnique device user id.text
start_tstampEarliest timestamp for the user's activity, based on derived_tstamp.timestamp_ntz
end_tstampLatest timestamp for the user's activity, based on derived_tstamp.timestamp_ntz
first_session_idThe UUID of the first session of a user e.g. c6ef3124-b53a-4b13-a233-0088f79dcbcb.text
last_session_idThe UUID of the last session of a user e.g. c6ef3124-b53a-4b13-a233-0088f79dcbcb.text
screen_viewsTotal number of screen views within a session.number
screen_names_viewedThe number of different screens viewed where the unique screens are counted by the screen names.number
sessionsTotal number of session for the user.number
sessions_duration_sTotal session duration for the specific user.number
active_daysTotal number of active days for the user.number
app_errorsTotal number of app errors.number
fatal_app_errorsTotoal number of fatal app errors.number
Code
Source
{{
config(
partition_by = snowplow_utils.get_value_by_target_type(bigquery_val={
"field": "start_tstamp",
"data_type": "timestamp"
}),
cluster_by=snowplow_utils.get_value_by_target_type(bigquery_val=["device_user_id"]),
sort='device_user_id',
dist='device_user_id',
sql_header=snowplow_utils.set_query_tag(var('snowplow__query_tag', 'snowplow_dbt'))
)
}}

select
device_user_id,
-- time
user_start_tstamp as start_tstamp,
user_end_tstamp as end_tstamp,
-- first/last session. Max to resolve edge case with multiple sessions with the same start/end tstamp
{% if target.type == 'postgres' %}
cast(max(case when start_tstamp = user_start_tstamp then cast(session_id as {{ type_string() }} ) end) as uuid) as first_session_id,
cast(max(case when end_tstamp = user_end_tstamp then cast(session_id as {{ type_string() }} ) end) as uuid) as last_session_id,
{% else %}
max(case when start_tstamp = user_start_tstamp then session_id end) as first_session_id,
max(case when end_tstamp = user_end_tstamp then session_id end) as last_session_id,
{% endif %}
-- engagement
sum(screen_views) as screen_views,
sum(screen_names_viewed) as screen_names_viewed,
count(distinct session_id) as sessions,
sum(session_duration_s) as sessions_duration_s,
count(distinct {{ date_trunc('day', 'start_tstamp') }}) as active_days,

sum(app_errors) as app_errors,
sum(fatal_app_errors) as fatal_app_errors

from {{ ref('snowplow_mobile_users_sessions_this_run') }}

group by 1,2,3

Depends On

Referenced By

Snowplow Mobile Users Lastsโ€‹

models/users/scratch/snowplow_mobile_users_lasts.sql

Description

This model identifies the last page view for a user and returns various dimensions associated with that page view.

Type: Table

Details

Columns
Column NameDescriptionType
device_user_idUnique device user id.text
last_screen_view_nameName of the last screen viewed.text
last_screen_view_transition_typeType of transition for the last screen view.text
last_screen_view_typeType of last screen view.text
last_carrierLast carrier provider for user.text
last_os_versionLast Operating System version for user device.text
Code
Source
{{ 
config(
sort='device_user_id',
dist='device_user_id',
sql_header=snowplow_utils.set_query_tag(var('snowplow__query_tag', 'snowplow_dbt'))
)
}}

select
a.device_user_id,
a.last_screen_view_name,
a.last_screen_view_transition_type,
a.last_screen_view_type,

a.carrier AS last_carrier,
a.os_version AS last_os_version

from {{ ref('snowplow_mobile_users_sessions_this_run') }} a

inner join {{ ref('snowplow_mobile_users_aggs') }} b
on a.session_id = b.last_session_id

Depends On

Referenced By

Snowplow Mobile Users Sessions This Runโ€‹

models/users/scratch/snowplow_mobile_users_sessions_this_run.sql

Description

This model contains all sessions data related to users contained in the given run of the Mobile model

Type: Table

Details

Columns
Column NameDescriptionType
app_idApplication ID e.g. angry-birds is used to distinguish different applications that are being tracked by the same Snowplow stack, e.g. production versus dev.text
session_idA visit / session UUID e.g. c6ef3124-b53a-4b13-a233-0088f79dcbcb.text
session_indexA visit / session index e.g. 3.number
previous_session_idA previous visit / session index e.g. 3.text
session_first_event_idA first visit / session index e.g. 3.text
session_last_event_idA last visit / session index e.g. 3.text
start_tstampTimestamp for the start of the session, based on derived_tstamp.timestamp_ntz
end_tstampTimestamp for the end of the session, based on derived_tstamp.timestamp_ntz
model_tstampThe current timestamp when the model processed this row.timestamp_ntz
user_idUnique ID set by business e.g. jon.doe@email.com.text
device_user_idUnique device user id.text
network_useridUser ID set by Snowplow using 3rd party cookie e.g. ecdff4d0-9175-40ac-a8bb-325c49733607.text
stitched_user_idtext
session_duration_sTotal duration of a session in seconds.number
has_installYes/No whether application is installed or not.boolean
screen_viewsTotal number of screen views within a session.number
screen_names_viewedThe number of different screens viewed where the unique screens are counted by the screen names.number
app_errorsTotal number of app errors.number
fatal_app_errorsTotoal number of fatal app errors.number
first_event_nameName of the first event fired in the session.text
last_event_nameName of the last event fired in the session.text
first_screen_view_nameName of the first screen viewed.text
first_screen_view_transition_typeType of transition for the first screen view.text
first_screen_view_typeType of first screen view.text
last_screen_view_nameName of the last screen viewed.text
last_screen_view_transition_typeType of transition for the last screen view.text
last_screen_view_typeType of last screen view.text
platformPlatform e.g. web.text
dvce_screenwidthScreen width in pixels e.g. 1900.number
dvce_screenheightScreen height in pixels e.g. 1024.number
device_manufacturerManufacturer name of the device eg. Apple.text
device_modelModel of the mobile device.text
os_typeType of OS running on the mobile device.text
os_versionOperation system full version.text
android_idfaIdentifier for Advertisers for Android devices.text
apple_idfaIdentifier for Advertisers for Apple devices.text
apple_idfvIdentifier for Vendors for Apple devices.text
open_idfaIdentifier for Vendors for Open devices.text
device_latitudeLatitude coordinates for device location.float
device_longitudeLongitude coordinates for device location.float
device_latitude_longitude_accuracyAccuracy of Latitude and Longitude coordinates for device location.float
device_altitudeAltitude coordinates for device location.float
device_altitude_accuracyAccuracy of device altitude coordinates.float
device_bearingHorizontal angle between device and true north.float
device_speedMobile device speed.float
geo_countryISO 3166-1 code for the country the visitor is located in e.g. GB, US.text
geo_regionISO-3166-2 code for country region the visitor is in e.g. I9, TX.text
geo_cityCity the visitor is in e.g. New York, London.text
geo_zipcodePostcode the visitor is in e.g. 94109.text
geo_latitudeVisitor location latitude e.g. 37.443604.float
geo_longitudeVisitor location longitude e.g. -122.4124.float
geo_region_nameVisitor region name e.g. Florida.text
geo_timezoneVisitor timezone name e.g. Europe/London.text
user_ipaddressUser IP address e.g. 92.231.54.234.text
useragentRaw useragent.text
name_trackerTracker namespace e.g. sp1.text
v_trackerTracker version e.g. js-3.0.0.text
carrierCarrier serivce provider used within device.text
network_technologytechnology used by the network provider of the device.text
network_typeType of network eg. 3G.text
first_buildFirst build of the application.text
last_buildLast build of the application.text
first_versionFirst application version.text
last_versionLast application version.text
user_start_tstampEarliest timestamp for the user's activity, based on derived_tstamp.timestamp_ntz
user_end_tstampLatest timestamp for the user's activity, based on derived_tstamp.timestamp_ntz
Code
Source
{{ 
config(
sort='start_tstamp',
dist='device_user_id',
tags=["this_run"],
sql_header=snowplow_utils.set_query_tag(var('snowplow__query_tag', 'snowplow_dbt'))
)
}}


with user_ids_this_run as (
select distinct device_user_id from {{ ref('snowplow_mobile_base_sessions_this_run') }}
)


select
a.*,
min(a.start_tstamp) over(partition by a.device_user_id) as user_start_tstamp,
max(a.end_tstamp) over(partition by a.device_user_id) as user_end_tstamp

from {{ var('snowplow__sessions_table') }} a
inner join user_ids_this_run b
on a.device_user_id = b.device_user_id

Depends On

Referenced By

Snowplow Mobile Users This Runโ€‹

models/users/scratch/snowplow_mobile_users_this_run.sql

Description

This staging table contains all the users for the given run of the Mobile model. It possess all the same columns as snowplow_mobile_users. If building a custom module that requires session level data, this is the table you should reference.

Type: Table

Details

Columns
Column NameDescriptionType
user_idUnique ID set by business e.g. jon.doe@email.com.text
device_user_idUnique device user id.text
network_useridUser ID set by Snowplow using 3rd party cookie e.g. ecdff4d0-9175-40ac-a8bb-325c49733607.text
start_tstampEarliest timestamp for the user's activity, based on derived_tstamp.timestamp_ntz
end_tstampLatest timestamp for the user's activity, based on derived_tstamp.timestamp_ntz
model_tstampThe current timestamp when the model processed this row.timestamp_tz
screen_viewsTotal number of screen views within a session.number
screen_names_viewedThe number of different screens viewed where the unique screens are counted by the screen names.number
sessionsTotal number of session for the user.number
sessions_duration_sTotal session duration for the specific user.number
active_daysTotal number of active days for the user.number
app_errorsTotal number of app errors.number
fatal_app_errorsTotoal number of fatal app errors.number
first_screen_view_nameName of the first screen viewed.text
first_screen_view_transition_typeType of transition for the first screen view.text
first_screen_view_typeType of first screen view.text
last_screen_view_nameName of the last screen viewed.text
last_screen_view_transition_typeType of transition for the last screen view.text
last_screen_view_typeType of last screen view.text
platformPlatform e.g. web.text
dvce_screenwidthScreen width in pixels e.g. 1900.number
dvce_screenheightScreen height in pixels e.g. 1024.number
device_manufacturerManufacturer name of the device eg. Apple.text
device_modelModel of the mobile device.text
os_typeType of OS running on the mobile device.text
first_os_versionFirst Operating System version for user device.text
last_os_versionLast Operating System version for user device.text
android_idfaIdentifier for Advertisers for Android devices.text
apple_idfaIdentifier for Advertisers for Apple devices.text
apple_idfvIdentifier for Vendors for Apple devices.text
open_idfaIdentifier for Vendors for Open devices.text
geo_countryISO 3166-1 code for the country the visitor is located in e.g. GB, US.text
geo_regionISO-3166-2 code for country region the visitor is in e.g. I9, TX.text
geo_cityCity the visitor is in e.g. New York, London.text
geo_zipcodePostcode the visitor is in e.g. 94109.text
geo_latitudeVisitor location latitude e.g. 37.443604.float
geo_longitudeVisitor location longitude e.g. -122.4124.float
geo_region_nameVisitor region name e.g. Florida.text
geo_timezoneVisitor timezone name e.g. Europe/London.text
first_carrierFirst carrier for user.text
last_carrierLast carrier provider for user.text
Code
Source
{{
config(
sort='start_tstamp',
dist='device_user_id',
tags=["this_run"],
sql_header=snowplow_utils.set_query_tag(var('snowplow__query_tag', 'snowplow_dbt'))
)
}}

select

-- user fields
a.user_id,
a.device_user_id,
a.network_userid,

b.start_tstamp,
b.end_tstamp,
{{ current_timestamp() }} AS model_tstamp,

-- engagement fields
b.screen_views,
b.screen_names_viewed,
b.sessions,
b.sessions_duration_s,
b.active_days,
--errors
b.app_errors,
b.fatal_app_errors,

-- screen fields
a.first_screen_view_name,
a.first_screen_view_transition_type,
a.first_screen_view_type,

c.last_screen_view_name,
c.last_screen_view_transition_type,
c.last_screen_view_type,

-- device fields
a.platform,
a.dvce_screenwidth,
a.dvce_screenheight,
a.device_manufacturer,
a.device_model,
a.os_type,
a.os_version first_os_version,
c.last_os_version,
a.android_idfa,
a.apple_idfa,
a.apple_idfv,
a.open_idfa,

-- geo fields
a.geo_country,
a.geo_region,
a.geo_city,
a.geo_zipcode,
a.geo_latitude,
a.geo_longitude,
a.geo_region_name,
a.geo_timezone,

a.carrier first_carrier,
c.last_carrier

from {{ ref('snowplow_mobile_users_aggs') }} as b

inner join {{ ref('snowplow_mobile_users_sessions_this_run') }} as a
on a.session_id = b.first_session_id

inner join {{ ref('snowplow_mobile_users_lasts') }} c
on b.device_user_id = c.device_user_id

Depends On

Referenced By

Was this page helpful?