sessions
2 years ago
create_city.txt
3 years ago
create_country.txt
3 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
3 years ago
get_countries.txt
2 years ago
get_country.txt
3 years ago
get_current_traffic.txt
3 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_campaigns.txt
52 lines
| 1 | SELECT |
| 2 | * |
| 3 | FROM ( |
| 4 | SELECT |
| 5 | GROUP_CONCAT(DISTINCT campaigns.campaign_id) AS campaign_ids, |
| 6 | initial_view_resource.id AS resource_id, |
| 7 | cached_title AS title, |
| 8 | utm_source, |
| 9 | utm_medium, |
| 10 | utm_campaign, |
| 11 | utm_term, |
| 12 | utm_content, |
| 13 | COUNT(DISTINCT IF(views.viewed_at BETWEEN :start AND :end, views.id, NULL)) AS views, |
| 14 | COUNT(DISTINCT IF(views.viewed_at BETWEEN :previous_start AND :previous_end, views.id, NULL)) AS previous_period_views, |
| 15 | COUNT(DISTINCT IF(views.viewed_at BETWEEN :start AND :end, sessions.visitor_id, NULL)) AS visitors, |
| 16 | COUNT(DISTINCT IF(views.viewed_at BETWEEN :previous_start AND :previous_end, sessions.visitor_id, NULL)) AS previous_period_visitors, |
| 17 | COUNT(DISTINCT IF(views.viewed_at BETWEEN :start AND :end, sessions.session_id, NULL)) AS sessions, |
| 18 | COUNT(DISTINCT IF(views.viewed_at BETWEEN :previous_start AND :previous_end, sessions.session_id, NULL)) AS previous_previous_sessions, |
| 19 | AVG( IF(views.viewed_at BETWEEN :start AND :end, TIMESTAMPDIFF(SECOND, sessions.created_at, sessions.ended_at), NULL)) AS average_session_duration, |
| 20 | 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, |
| 21 | COUNT(DISTINCT IF(views.viewed_at BETWEEN :start AND :end AND sessions.final_view_id IS NULL, sessions.session_id, NULL)) AS bounces, |
| 22 | SUM( IF(views.viewed_at BETWEEN :start AND :end, wc.orders, NULL)) AS wc_orders, |
| 23 | SUM( IF(views.viewed_at BETWEEN :start AND :end, wc.gross_sales, NULL)) AS wc_gross_sales, |
| 24 | SUM( IF(views.viewed_at BETWEEN :start AND :end, wc.total_refunds, NULL)) AS wc_refunds, |
| 25 | SUM( IF(views.viewed_at BETWEEN :start AND :end, wc.total_refunded, NULL)) AS wc_refunded_amount |
| 26 | FROM |
| 27 | wp_independent_analytics_views AS views |
| 28 | LEFT JOIN wp_independent_analytics_sessions AS sessions ON views.session_id = sessions.session_id |
| 29 | JOIN wp_independent_analytics_campaigns AS campaigns ON sessions.campaign_id = campaigns.campaign_id |
| 30 | JOIN wp_independent_analytics_views AS initial_view ON sessions.initial_view_id = initial_view.id |
| 31 | JOIN wp_independent_analytics_resources AS initial_view_resource ON initial_view.resource_id = initial_view_resource.id |
| 32 | JOIN ( |
| 33 | SELECT |
| 34 | views.session_id, |
| 35 | COUNT(DISTINCT wc_orders.order_id) AS orders, |
| 36 | IFNULL(SUM(wc_orders.total), 0) AS gross_sales, |
| 37 | IFNULL(SUM(wc_orders.total_refunded), 0) AS total_refunded, |
| 38 | IFNULL(SUM(wc_orders.total_refunds), 0) AS total_refunds |
| 39 | FROM |
| 40 | wp_independent_analytics_views AS views |
| 41 | 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') |
| 42 | GROUP BY |
| 43 | views.session_id) AS wc ON wc.session_id = sessions.session_id |
| 44 | WHERE |
| 45 | views.viewed_at BETWEEN :previous_start AND :end |
| 46 | GROUP BY |
| 47 | campaigns.campaign_id, |
| 48 | initial_view_resource.id |
| 49 | ORDER BY |
| 50 | visitors DESC) AS subquery |
| 51 | WHERE |
| 52 | views > 0 OR previous_period_views > 0 |