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_countries.txt
47 lines
| 1 | SELECT |
| 2 | * |
| 3 | FROM ( |
| 4 | SELECT |
| 5 | countries.country_code, |
| 6 | countries.country, |
| 7 | countries.continent, |
| 8 | GROUP_CONCAT(DISTINCT countries.country_id) AS country_ids, |
| 9 | COUNT(DISTINCT IF(views.viewed_at BETWEEN :start AND :end, views.id, NULL)) AS views, |
| 10 | COUNT(DISTINCT IF(views.viewed_at BETWEEN :previous_start AND :previous_end, views.id, NULL)) AS previous_period_views, |
| 11 | COUNT(DISTINCT IF(views.viewed_at BETWEEN :start AND :end, sessions.visitor_id, NULL)) AS visitors, |
| 12 | COUNT(DISTINCT IF(views.viewed_at BETWEEN :previous_start AND :previous_end, sessions.visitor_id, NULL)) AS previous_period_visitors, |
| 13 | COUNT(DISTINCT IF(views.viewed_at BETWEEN :start AND :end, sessions.session_id, NULL)) AS sessions, |
| 14 | COUNT(DISTINCT IF(views.viewed_at BETWEEN :previous_start AND :previous_end, sessions.session_id, NULL)) AS previous_previous_sessions, |
| 15 | AVG( IF(views.viewed_at BETWEEN :start AND :end, TIMESTAMPDIFF(SECOND, sessions.created_at, sessions.ended_at), NULL)) AS average_session_duration, |
| 16 | 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, |
| 17 | COUNT(DISTINCT IF(views.viewed_at BETWEEN :start AND :end AND sessions.final_view_id IS NULL, sessions.session_id, NULL)) AS bounces, |
| 18 | SUM( IF(views.viewed_at BETWEEN :start AND :end, wc.orders, NULL)) AS wc_orders, |
| 19 | SUM( IF(views.viewed_at BETWEEN :start AND :end, wc.gross_sales, NULL)) AS wc_gross_sales, |
| 20 | SUM( IF(views.viewed_at BETWEEN :start AND :end, wc.total_refunds, NULL)) AS wc_refunds, |
| 21 | SUM( IF(views.viewed_at BETWEEN :start AND :end, wc.total_refunded, NULL)) AS wc_refunded_amount |
| 22 | FROM |
| 23 | wp_independent_analytics_views AS views |
| 24 | LEFT JOIN wp_independent_analytics_sessions AS sessions ON views.session_id = sessions.session_id |
| 25 | JOIN wp_independent_analytics_countries AS countries ON sessions.country_id = countries.country_id |
| 26 | JOIN ( |
| 27 | SELECT |
| 28 | views.session_id, |
| 29 | COUNT(DISTINCT wc_orders.order_id) AS orders, |
| 30 | IFNULL(SUM(wc_orders.total), 0) AS gross_sales, |
| 31 | IFNULL(SUM(wc_orders.total_refunded), 0) AS total_refunded, |
| 32 | IFNULL(SUM(wc_orders.total_refunds), 0) AS total_refunds |
| 33 | FROM |
| 34 | wp_independent_analytics_views AS views |
| 35 | LEFT JOIN wp_independent_analytics_wc_orders AS wc_orders ON views.id = wc_orders.view_id AND wc_orders.status IN('wc-completed', 'completed', 'wc-processing', 'processing', 'wc-refunded', 'refunded') |
| 36 | GROUP BY |
| 37 | views.session_id) AS wc ON wc.session_id = sessions.session_id |
| 38 | WHERE |
| 39 | views.viewed_at BETWEEN :previous_start AND :end |
| 40 | GROUP BY |
| 41 | sessions.country_id |
| 42 | ORDER BY |
| 43 | visitors DESC, |
| 44 | views DESC, |
| 45 | country) AS subquery |
| 46 | WHERE |
| 47 | views > 0 OR previous_period_views > 0 |