sessions
2 years ago
create_city.txt
2 years ago
create_country.txt
2 years ago
create_referrer.txt
3 years ago
create_resource.txt
3 years ago
create_view.txt
3 years ago
get_campaign.txt
3 years ago
get_campaigns.txt
2 years ago
get_cities.txt
2 years ago
get_city.txt
2 years ago
get_countries.txt
2 years ago
get_country.txt
2 years ago
get_current_traffic.txt
2 years ago
get_device_browsers.txt
2 years ago
get_device_operating_systems.txt
2 years ago
get_device_types.txt
2 years ago
get_referrer.txt
3 years ago
get_referrers.txt
2 years ago
get_resource.txt
3 years ago
get_resources.txt
2 years ago
get_visitors_by_minute_interval.txt
3 years ago
get_visitors_by_ten_second_interval.txt
3 years ago
get_device_types.txt
45 lines
| 1 | SELECT |
| 2 | * |
| 3 | FROM ( |
| 4 | SELECT |
| 5 | GROUP_CONCAT(DISTINCT devices.device_id) AS device_ids, |
| 6 | devices.type AS type, |
| 7 | COUNT(DISTINCT IF(views.viewed_at BETWEEN :start AND :end, views.id, NULL)) AS views, |
| 8 | COUNT(DISTINCT IF(views.viewed_at BETWEEN :previous_start AND :previous_end, views.id, NULL)) AS previous_period_views, |
| 9 | COUNT(DISTINCT IF(views.viewed_at BETWEEN :start AND :end, sessions.visitor_id, NULL)) AS visitors, |
| 10 | COUNT(DISTINCT IF(views.viewed_at BETWEEN :previous_start AND :previous_end, sessions.visitor_id, NULL)) AS previous_period_visitors, |
| 11 | COUNT(DISTINCT IF(views.viewed_at BETWEEN :start AND :end, sessions.session_id, NULL)) AS sessions, |
| 12 | COUNT(DISTINCT IF(views.viewed_at BETWEEN :previous_start AND :previous_end, sessions.session_id, NULL)) AS previous_previous_sessions, |
| 13 | AVG( IF(views.viewed_at BETWEEN :start AND :end, TIMESTAMPDIFF(SECOND, sessions.created_at, sessions.ended_at), NULL)) AS average_session_duration, |
| 14 | AVG( IF(views.viewed_at BETWEEN :previous_start AND :previous_end, TIMESTAMPDIFF(SECOND, sessions.created_at, sessions.ended_at), NULL)) AS previous_period_average_session_duration, |
| 15 | COUNT(DISTINCT IF(views.viewed_at BETWEEN :start AND :end AND sessions.final_view_id IS NULL, sessions.session_id, NULL)) AS bounces, |
| 16 | SUM( IF(views.viewed_at BETWEEN :start AND :end, wc.orders, NULL)) AS wc_orders, |
| 17 | SUM( IF(views.viewed_at BETWEEN :start AND :end, wc.gross_sales, NULL)) AS wc_gross_sales, |
| 18 | SUM( IF(views.viewed_at BETWEEN :start AND :end, wc.total_refunds, NULL)) AS wc_refunds, |
| 19 | SUM( IF(views.viewed_at BETWEEN :start AND :end, wc.total_refunded, NULL)) AS wc_refunded_amount |
| 20 | FROM |
| 21 | wp_independent_analytics_views AS views |
| 22 | LEFT JOIN wp_independent_analytics_sessions AS sessions ON views.session_id = sessions.session_id |
| 23 | JOIN wp_independent_analytics_devices AS devices ON sessions.device_id = devices.device_id |
| 24 | JOIN ( |
| 25 | SELECT |
| 26 | views.id AS view_id, |
| 27 | COUNT(DISTINCT wc_orders.order_id) AS orders, |
| 28 | IFNULL(SUM(wc_orders.total), 0) AS gross_sales, |
| 29 | IFNULL(SUM(wc_orders.total_refunded), 0) AS total_refunded, |
| 30 | IFNULL(SUM(wc_orders.total_refunds), 0) AS total_refunds |
| 31 | FROM |
| 32 | wp_independent_analytics_views AS views |
| 33 | LEFT JOIN wp_independent_analytics_wc_orders AS wc_orders ON views.id = wc_orders.view_id |
| 34 | AND wc_orders.status IN('wc-completed', 'completed', 'wc-processing', 'processing', 'wc-refunded', 'refunded') |
| 35 | GROUP BY |
| 36 | views.id) AS wc ON wc.view_id = views.id |
| 37 | WHERE |
| 38 | views.viewed_at BETWEEN :previous_start AND :end |
| 39 | GROUP BY |
| 40 | devices.type |
| 41 | ORDER BY |
| 42 | visitors DESC) AS subquery |
| 43 | WHERE |
| 44 | views > 0 OR previous_period_views > 0 |
| 45 |