|
| 1 | +DESCRIPTION > |
| 2 | + Parsed `page_hit` events, implementing `browser` and `device` detection logic. |
| 3 | + |
| 4 | + |
| 5 | +TOKEN "dashboard" READ |
| 6 | + |
| 7 | +NODE parsed_hits |
| 8 | +DESCRIPTION > |
| 9 | + Parse raw page_hit events |
| 10 | + |
| 11 | +SQL > |
| 12 | + |
| 13 | + SELECT |
| 14 | + timestamp, |
| 15 | + action, |
| 16 | + version, |
| 17 | + coalesce(session_id, '0') as session_id, |
| 18 | + JSONExtractString(payload, 'locale') as locale, |
| 19 | + JSONExtractString(payload, 'location') as location, |
| 20 | + JSONExtractString(payload, 'referrer') as referrer, |
| 21 | + JSONExtractString(payload, 'pathname') as pathname, |
| 22 | + JSONExtractString(payload, 'href') as href, |
| 23 | + lower(JSONExtractString(payload, 'user-agent')) as user_agent |
| 24 | + FROM analytics_events |
| 25 | + where action = 'page_hit' |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | +NODE endpoint |
| 30 | +SQL > |
| 31 | + |
| 32 | + SELECT |
| 33 | + timestamp, |
| 34 | + action, |
| 35 | + version, |
| 36 | + session_id, |
| 37 | + location, |
| 38 | + referrer, |
| 39 | + pathname, |
| 40 | + href, |
| 41 | + case |
| 42 | + when match(user_agent, 'wget|ahrefsbot|curl|urllib|bitdiscovery|\+https://|googlebot') |
| 43 | + then 'bot' |
| 44 | + when match(user_agent, 'android') |
| 45 | + then 'mobile-android' |
| 46 | + when match(user_agent, 'ipad|iphone|ipod') |
| 47 | + then 'mobile-ios' |
| 48 | + else 'desktop' |
| 49 | + END as device, |
| 50 | + case |
| 51 | + when match(user_agent, 'firefox') |
| 52 | + then 'firefox' |
| 53 | + when match(user_agent, 'chrome|crios') |
| 54 | + then 'chrome' |
| 55 | + when match(user_agent, 'opera') |
| 56 | + then 'opera' |
| 57 | + when match(user_agent, 'msie|trident') |
| 58 | + then 'ie' |
| 59 | + when match(user_agent, 'iphone|ipad|safari') |
| 60 | + then 'safari' |
| 61 | + else 'Unknown' |
| 62 | + END as browser |
| 63 | + FROM parsed_hits |
| 64 | + |
| 65 | + |
0 commit comments