-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
311 additions
and
309 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
TOKEN tracker APPEND | ||
|
||
DESCRIPTION > | ||
Analytics events landing data source | ||
|
||
TOKEN "tracker" APPEND | ||
|
||
SCHEMA > | ||
`timestamp` DateTime `json:$.timestamp`, | ||
`session_id` String `json:$.session_id`, | ||
`action` LowCardinality(String) `json:$.action`, | ||
`version` LowCardinality(String) `json:$.version`, | ||
`payload` String `json:$.payload` | ||
|
||
ENGINE "MergeTree" | ||
ENGINE_PARTITION_KEY "toYYYYMM(timestamp)" | ||
ENGINE_SORTING_KEY "timestamp" | ||
ENGINE_TTL "timestamp + toIntervalDay(60)" | ||
ENGINE MergeTree | ||
ENGINE_PARTITION_KEY toYYYYMM(timestamp) | ||
ENGINE_SORTING_KEY timestamp | ||
ENGINE_TTL timestamp + toIntervalDay(60) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
SCHEMA > | ||
`date` Date, | ||
`device` String, | ||
`browser` String, | ||
`location` String, | ||
`pathname` String, | ||
`visits` AggregateFunction(uniq, String), | ||
`hits` AggregateFunction(count) | ||
|
||
ENGINE AggregatingMergeTree | ||
ENGINE_PARTITION_KEY toYYYYMM(date) | ||
ENGINE_SORTING_KEY date, device, browser, location, pathname |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
SCHEMA > | ||
`date` Date, | ||
`session_id` String, | ||
`device` SimpleAggregateFunction(any, String), | ||
`browser` SimpleAggregateFunction(any, String), | ||
`location` SimpleAggregateFunction(any, String), | ||
`first_hit` SimpleAggregateFunction(min, DateTime), | ||
`latest_hit` SimpleAggregateFunction(max, DateTime), | ||
`hits` AggregateFunction(count) | ||
|
||
ENGINE AggregatingMergeTree | ||
ENGINE_PARTITION_KEY toYYYYMM(date) | ||
ENGINE_SORTING_KEY date, session_id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
SCHEMA > | ||
`date` Date, | ||
`device` String, | ||
`browser` String, | ||
`location` String, | ||
`referrer` String, | ||
`visits` AggregateFunction(uniq, String), | ||
`hits` AggregateFunction(count) | ||
|
||
ENGINE AggregatingMergeTree | ||
ENGINE_PARTITION_KEY toYYYYMM(date) | ||
ENGINE_SORTING_KEY date, device, browser, location, referrer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,58 @@ | ||
TOKEN dashboard READ | ||
|
||
DESCRIPTION > | ||
Parsed `page_hit` events, implementing `browser` and `device` detection logic. | ||
|
||
TOKEN "dashboard" READ | ||
|
||
NODE parsed_hits | ||
DESCRIPTION > | ||
Parse raw page_hit events | ||
|
||
SQL > | ||
SELECT | ||
timestamp, | ||
action, | ||
version, | ||
coalesce(session_id,'0') as session_id, | ||
JSONExtractString(payload, 'locale') as locale, | ||
JSONExtractString(payload, 'location') as location, | ||
JSONExtractString(payload, 'referrer') as referrer, | ||
JSONExtractString(payload, 'pathname') as pathname, | ||
JSONExtractString(payload, 'href') as href, | ||
lower(JSONExtractString(payload, 'user-agent')) as user_agent | ||
FROM | ||
analytics_events | ||
timestamp, | ||
action, | ||
version, | ||
coalesce(session_id, '0') as session_id, | ||
JSONExtractString(payload, 'locale') as locale, | ||
JSONExtractString(payload, 'location') as location, | ||
JSONExtractString(payload, 'referrer') as referrer, | ||
JSONExtractString(payload, 'pathname') as pathname, | ||
JSONExtractString(payload, 'href') as href, | ||
lower(JSONExtractString(payload, 'user-agent')) as user_agent | ||
FROM analytics_events | ||
where action = 'page_hit' | ||
|
||
NODE endpoint | ||
SQL > | ||
SELECT | ||
timestamp, | ||
action, | ||
version, | ||
session_id, | ||
location, | ||
referrer, | ||
pathname, | ||
href, | ||
case | ||
when match(user_agent, 'wget|ahrefsbot|curl|urllib|bitdiscovery|\+https://|googlebot') then 'bot' | ||
when match(user_agent, 'android') then 'mobile-android' | ||
when match(user_agent, 'ipad|iphone|ipod') then 'mobile-ios' | ||
else 'desktop' | ||
END as device, | ||
case | ||
when match(user_agent, 'firefox') then 'firefox' | ||
when match(user_agent, 'chrome|crios') then 'chrome' | ||
when match(user_agent, 'opera') then 'opera' | ||
when match(user_agent, 'msie|trident') then 'ie' | ||
when match(user_agent, 'iphone|ipad|safari') then 'safari' | ||
else 'Unknown' | ||
END as browser | ||
FROM | ||
parsed_hits | ||
timestamp, | ||
action, | ||
version, | ||
session_id, | ||
location, | ||
referrer, | ||
pathname, | ||
href, | ||
case | ||
when match(user_agent, 'wget|ahrefsbot|curl|urllib|bitdiscovery|\+https://|googlebot') | ||
then 'bot' | ||
when match(user_agent, 'android') | ||
then 'mobile-android' | ||
when match(user_agent, 'ipad|iphone|ipod') | ||
then 'mobile-ios' | ||
else 'desktop' | ||
END as device, | ||
case | ||
when match(user_agent, 'firefox') | ||
then 'firefox' | ||
when match(user_agent, 'chrome|crios') | ||
then 'chrome' | ||
when match(user_agent, 'opera') | ||
then 'opera' | ||
when match(user_agent, 'msie|trident') | ||
then 'ie' | ||
when match(user_agent, 'iphone|ipad|safari') | ||
then 'safari' | ||
else 'Unknown' | ||
END as browser | ||
FROM parsed_hits |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.