|
| 1 | +import { Analytics } from '../../types/tables'; |
| 2 | +import type { SimpleQueryConfig } from '../types'; |
| 3 | + |
| 4 | +export const EngagementBuilders: Record<string, SimpleQueryConfig> = { |
| 5 | + scroll_depth_summary: { |
| 6 | + meta: { |
| 7 | + title: 'Scroll Depth Summary', |
| 8 | + description: |
| 9 | + 'Average scroll depth metrics showing how far users scroll on pages.', |
| 10 | + category: 'Engagement', |
| 11 | + tags: ['scroll', 'engagement', 'user behavior'], |
| 12 | + output_fields: [ |
| 13 | + { |
| 14 | + name: 'avg_scroll_depth', |
| 15 | + type: 'number', |
| 16 | + label: 'Average Scroll Depth', |
| 17 | + description: 'Average percentage of page scrolled', |
| 18 | + unit: '%', |
| 19 | + }, |
| 20 | + { |
| 21 | + name: 'total_sessions', |
| 22 | + type: 'number', |
| 23 | + label: 'Total Sessions', |
| 24 | + description: 'Total sessions with scroll data', |
| 25 | + }, |
| 26 | + ], |
| 27 | + default_visualization: 'metric', |
| 28 | + supports_granularity: ['hour', 'day'], |
| 29 | + version: '1.0', |
| 30 | + }, |
| 31 | + table: Analytics.events, |
| 32 | + fields: [ |
| 33 | + 'ROUND(AVG(CASE WHEN scroll_depth > 0 THEN scroll_depth * 100 ELSE NULL END), 1) as avg_scroll_depth', |
| 34 | + 'COUNT(DISTINCT session_id) as total_sessions', |
| 35 | + 'COUNT(DISTINCT anonymous_id) as visitors', |
| 36 | + ], |
| 37 | + where: ["event_name = 'screen_view'", 'scroll_depth > 0'], |
| 38 | + timeField: 'time', |
| 39 | + customizable: true, |
| 40 | + }, |
| 41 | + |
| 42 | + scroll_depth_distribution: { |
| 43 | + meta: { |
| 44 | + title: 'Scroll Depth Distribution', |
| 45 | + description: |
| 46 | + 'Breakdown of users by how far they scroll on pages, grouped into ranges.', |
| 47 | + category: 'Engagement', |
| 48 | + tags: ['scroll', 'distribution', 'engagement'], |
| 49 | + output_fields: [ |
| 50 | + { |
| 51 | + name: 'depth_range', |
| 52 | + type: 'string', |
| 53 | + label: 'Scroll Range', |
| 54 | + description: 'Percentage range of page scrolled', |
| 55 | + }, |
| 56 | + { |
| 57 | + name: 'visitors', |
| 58 | + type: 'number', |
| 59 | + label: 'Visitors', |
| 60 | + description: 'Unique visitors in this range', |
| 61 | + }, |
| 62 | + { |
| 63 | + name: 'sessions', |
| 64 | + type: 'number', |
| 65 | + label: 'Sessions', |
| 66 | + description: 'Sessions in this range', |
| 67 | + }, |
| 68 | + { |
| 69 | + name: 'percentage', |
| 70 | + type: 'number', |
| 71 | + label: 'Share', |
| 72 | + description: 'Percentage of total sessions', |
| 73 | + unit: '%', |
| 74 | + }, |
| 75 | + ], |
| 76 | + default_visualization: 'bar', |
| 77 | + supports_granularity: ['hour', 'day'], |
| 78 | + version: '1.0', |
| 79 | + }, |
| 80 | + table: Analytics.events, |
| 81 | + fields: [ |
| 82 | + 'CASE ' + |
| 83 | + 'WHEN scroll_depth < 0.25 THEN "0-25%" ' + |
| 84 | + 'WHEN scroll_depth < 0.5 THEN "25-50%" ' + |
| 85 | + 'WHEN scroll_depth < 0.75 THEN "50-75%" ' + |
| 86 | + 'WHEN scroll_depth < 1.0 THEN "75-100%" ' + |
| 87 | + 'ELSE "100%" ' + |
| 88 | + 'END as depth_range', |
| 89 | + 'COUNT(DISTINCT anonymous_id) as visitors', |
| 90 | + 'COUNT(DISTINCT session_id) as sessions', |
| 91 | + 'ROUND((COUNT(DISTINCT session_id) / SUM(COUNT(DISTINCT session_id)) OVER()) * 100, 2) as percentage', |
| 92 | + ], |
| 93 | + where: ["event_name = 'screen_view'", 'scroll_depth > 0'], |
| 94 | + groupBy: ['depth_range'], |
| 95 | + orderBy: |
| 96 | + 'CASE depth_range WHEN "0-25%" THEN 1 WHEN "25-50%" THEN 2 WHEN "50-75%" THEN 3 WHEN "75-100%" THEN 4 ELSE 5 END', |
| 97 | + timeField: 'time', |
| 98 | + customizable: true, |
| 99 | + }, |
| 100 | + |
| 101 | + page_scroll_performance: { |
| 102 | + meta: { |
| 103 | + title: 'Page Scroll Performance', |
| 104 | + description: |
| 105 | + 'Average scroll depth by page, showing which pages engage users most effectively.', |
| 106 | + category: 'Engagement', |
| 107 | + tags: ['pages', 'scroll', 'performance'], |
| 108 | + output_fields: [ |
| 109 | + { |
| 110 | + name: 'name', |
| 111 | + type: 'string', |
| 112 | + label: 'Page Path', |
| 113 | + description: 'The page URL path', |
| 114 | + }, |
| 115 | + { |
| 116 | + name: 'avg_scroll_depth', |
| 117 | + type: 'number', |
| 118 | + label: 'Avg Scroll Depth', |
| 119 | + description: 'Average scroll depth percentage', |
| 120 | + unit: '%', |
| 121 | + }, |
| 122 | + { |
| 123 | + name: 'visitors', |
| 124 | + type: 'number', |
| 125 | + label: 'Visitors', |
| 126 | + description: 'Unique visitors to this page', |
| 127 | + }, |
| 128 | + { |
| 129 | + name: 'sessions', |
| 130 | + type: 'number', |
| 131 | + label: 'Sessions', |
| 132 | + description: 'Sessions on this page', |
| 133 | + }, |
| 134 | + ], |
| 135 | + default_visualization: 'table', |
| 136 | + supports_granularity: ['hour', 'day'], |
| 137 | + version: '1.0', |
| 138 | + }, |
| 139 | + table: Analytics.events, |
| 140 | + fields: [ |
| 141 | + "trimRight(path(path), '/') as name", |
| 142 | + 'ROUND(AVG(CASE WHEN scroll_depth > 0 THEN scroll_depth * 100 ELSE NULL END), 1) as avg_scroll_depth', |
| 143 | + 'COUNT(DISTINCT anonymous_id) as visitors', |
| 144 | + 'COUNT(DISTINCT session_id) as sessions', |
| 145 | + 'COUNT(*) as pageviews', |
| 146 | + ], |
| 147 | + where: ["event_name = 'screen_view'", "path != ''", 'scroll_depth > 0'], |
| 148 | + groupBy: ["trimRight(path(path), '/')"], |
| 149 | + orderBy: 'avg_scroll_depth DESC', |
| 150 | + limit: 100, |
| 151 | + timeField: 'time', |
| 152 | + allowedFilters: [ |
| 153 | + 'path', |
| 154 | + 'country', |
| 155 | + 'device_type', |
| 156 | + 'browser_name', |
| 157 | + 'os_name', |
| 158 | + 'referrer', |
| 159 | + ], |
| 160 | + customizable: true, |
| 161 | + }, |
| 162 | + |
| 163 | + interaction_summary: { |
| 164 | + meta: { |
| 165 | + title: 'Interaction Summary', |
| 166 | + description: |
| 167 | + 'Summary of user interactions including click, scroll, and keyboard events.', |
| 168 | + category: 'Engagement', |
| 169 | + tags: ['interactions', 'engagement', 'user behavior'], |
| 170 | + output_fields: [ |
| 171 | + { |
| 172 | + name: 'avg_interactions', |
| 173 | + type: 'number', |
| 174 | + label: 'Average Interactions', |
| 175 | + description: 'Average number of interactions per session', |
| 176 | + }, |
| 177 | + { |
| 178 | + name: 'interactive_sessions', |
| 179 | + type: 'number', |
| 180 | + label: 'Interactive Sessions', |
| 181 | + description: 'Sessions with at least one interaction', |
| 182 | + }, |
| 183 | + { |
| 184 | + name: 'interaction_rate', |
| 185 | + type: 'number', |
| 186 | + label: 'Interaction Rate', |
| 187 | + description: 'Percentage of sessions with interactions', |
| 188 | + unit: '%', |
| 189 | + }, |
| 190 | + ], |
| 191 | + default_visualization: 'metric', |
| 192 | + supports_granularity: ['hour', 'day'], |
| 193 | + version: '1.0', |
| 194 | + }, |
| 195 | + table: Analytics.events, |
| 196 | + fields: [ |
| 197 | + 'ROUND(AVG(CASE WHEN interaction_count >= 0 THEN interaction_count ELSE NULL END), 1) as avg_interactions', |
| 198 | + 'COUNT(DISTINCT CASE WHEN interaction_count > 0 THEN session_id ELSE NULL END) as interactive_sessions', |
| 199 | + 'ROUND((COUNT(DISTINCT CASE WHEN interaction_count > 0 THEN session_id ELSE NULL END) / COUNT(DISTINCT session_id)) * 100, 1) as interaction_rate', |
| 200 | + 'COUNT(DISTINCT session_id) as total_sessions', |
| 201 | + ], |
| 202 | + where: ["event_name = 'screen_view'", 'interaction_count >= 0'], |
| 203 | + timeField: 'time', |
| 204 | + customizable: true, |
| 205 | + }, |
| 206 | +}; |
0 commit comments