PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 2.13.6
Independent Analytics – WordPress Analytics Plugin v2.13.6
2.15.5 2.15.4 2.15.3 2.15.2 2.15.1 2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 1.19.1 1.2 1.20.0 1.21.0 1.22.0 1.22.1 1.23.0 1.23.1 1.24.0 1.24.1 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.28.1 1.28.2 1.28.3 1.29.0 1.3 1.30.0 1.30.1 1.4 1.5 1.6 1.7 1.8 1.9 2.0.0 2.0.1 2.1.4 2.1.5 2.1.6 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.10 2.11.2 2.11.3 2.11.4 2.11.5 2.11.6 2.11.7 2.11.8 2.11.9 2.12.0 2.12.1 2.12.2 2.13.1 2.13.2 2.13.5 2.13.6 2.14.0 2.14.1 2.14.2 2.14.4 2.14.6 2.14.7 2.14.8 2.14.9 2.2.0 2.2.1 2.3.1 2.3.2 2.4.2 2.4.3 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.7.1 2.7.2 2.7.3 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7
independent-analytics / IAWP / Rows / Device_OSS.php
independent-analytics / IAWP / Rows Last commit date
Campaign_Landing_Pages.php 10 months ago Campaign_UTM_Campaigns.php 10 months ago Campaign_UTM_Mediums.php 10 months ago Campaign_UTM_Sources.php 10 months ago Campaigns.php 10 months ago Cities.php 10 months ago Countries.php 10 months ago Device_Browsers.php 10 months ago Device_OSS.php 10 months ago Device_Types.php 10 months ago Filter.php 9 months ago Forms.php 10 months ago Link_Patterns.php 9 months ago Links.php 9 months ago Pages.php 10 months ago Referrer_Types.php 10 months ago Referrers.php 10 months ago Rows.php 10 months ago
Device_OSS.php
88 lines
1 <?php
2
3 namespace IAWP\Rows;
4
5 use IAWP\Form_Submissions\Form;
6 use IAWP\Illuminate_Builder;
7 use IAWP\Models\Device;
8 use IAWP\Query;
9 use IAWP\Query_Taps;
10 use IAWPSCOPED\Illuminate\Database\Query\Builder;
11 use IAWPSCOPED\Illuminate\Database\Query\JoinClause;
12 /** @internal */
13 class Device_OSS extends \IAWP\Rows\Rows
14 {
15 public function attach_filters(Builder $query) : void
16 {
17 $query->joinSub($this->query(\true), 'device_os_rows', function (JoinClause $join) {
18 $join->on('device_os_rows.device_os_id', '=', 'sessions.device_os_id');
19 });
20 }
21 protected function fetch_rows() : array
22 {
23 $rows = $this->query()->get()->all();
24 return \array_map(function ($row) {
25 return new Device($row);
26 }, $rows);
27 }
28 protected function sort_tie_breaker_column() : string
29 {
30 return 'os';
31 }
32 private function query(?bool $skip_pagination = \false) : Builder
33 {
34 if ($skip_pagination) {
35 $this->number_of_rows = null;
36 }
37 $views_table = Query::get_table_name(Query::VIEWS);
38 $sessions_table = Query::get_table_name(Query::SESSIONS);
39 $orders_table = Query::get_table_name(Query::ORDERS);
40 $device_oss_table = Query::get_table_name(Query::DEVICE_OSS);
41 $session_statistics = Illuminate_Builder::new();
42 $session_statistics->select('sessions.*')->selectRaw('COUNT(DISTINCT views.id) AS views')->selectRaw('COUNT(DISTINCT clicks.click_id) AS clicks')->selectRaw('COUNT(DISTINCT orders.order_id) AS wc_orders')->selectRaw('IFNULL(CAST(SUM(orders.total) AS SIGNED), 0) AS wc_gross_sales')->selectRaw('IFNULL(CAST(SUM(orders.total_refunded) AS SIGNED), 0) AS wc_refunded_amount')->selectRaw('IFNULL(CAST(SUM(orders.total_refunds) AS SIGNED), 0) AS wc_refunds')->selectRaw('IFNULL(SUM(form_submissions.form_submissions), 0) AS form_submissions')->tap(function (Builder $query) {
43 foreach (Form::get_forms() as $form) {
44 $query->selectRaw("SUM(IF(form_submissions.form_id = ?, form_submissions.form_submissions, 0)) AS {$form->submissions_column()}", [$form->id()]);
45 }
46 })->from("{$sessions_table} AS sessions")->join("{$views_table} AS views", function (JoinClause $join) {
47 $join->on('sessions.session_id', '=', 'views.session_id');
48 })->leftJoin("{$orders_table} AS orders", function (JoinClause $join) {
49 $join->on('views.id', '=', 'orders.initial_view_id')->where('orders.is_included_in_analytics', '=', \true);
50 })->leftJoin("{$this->tables::clicks()} AS clicks", function (JoinClause $join) {
51 $join->on('views.id', '=', 'clicks.view_id');
52 })->tap(Query_Taps::tap_authored_content_check())->tap(Query_Taps::tap_related_to_examined_record($this->examiner_config))->when(!$this->appears_to_be_for_real_time_analytics(), function (Builder $query) {
53 $query->whereBetween('sessions.created_at', $this->get_current_period_iso_range());
54 })->whereBetween('views.viewed_at', $this->get_current_period_iso_range())->leftJoinSub($this->get_form_submissions_query(), 'form_submissions', function (JoinClause $join) {
55 $join->on('form_submissions.view_id', '=', 'views.id');
56 })->whereNotNull('sessions.device_os_id')->groupBy('sessions.session_id');
57 $device_oss_query = Illuminate_Builder::new();
58 $device_oss_query->select('device_oss.device_os_id', 'device_oss.device_os AS os')->selectRaw('IFNULL(CAST(SUM(sessions.views) AS SIGNED), 0) AS views')->selectRaw('COUNT(DISTINCT sessions.visitor_id) AS visitors')->selectRaw('COUNT(DISTINCT sessions.session_id) AS sessions')->selectRaw('ROUND(AVG( TIMESTAMPDIFF(SECOND, sessions.created_at, sessions.ended_at))) AS average_session_duration')->selectRaw('COUNT(DISTINCT IF(sessions.final_view_id IS NULL, sessions.session_id, NULL)) AS bounces')->selectRaw('SUM(sessions.clicks) AS clicks')->selectRaw('SUM(sessions.wc_orders) AS wc_orders')->selectRaw('SUM(sessions.wc_gross_sales) AS wc_gross_sales')->selectRaw('SUM(sessions.wc_refunded_amount) AS wc_refunded_amount')->selectRaw('SUM(sessions.wc_refunds) AS wc_refunds')->selectRaw('SUM(sessions.form_submissions) AS form_submissions')->tap(function (Builder $query) {
59 foreach (Form::get_forms() as $form) {
60 $query->selectRaw("SUM(sessions.{$form->submissions_column()}) AS {$form->submissions_column()}");
61 }
62 })->fromSub($session_statistics, 'sessions')->join($device_oss_query->raw($device_oss_table . ' AS device_oss'), function (JoinClause $join) {
63 $join->on('sessions.device_os_id', '=', 'device_oss.device_os_id');
64 })->when(!$this->appears_to_be_for_real_time_analytics(), function (Builder $query) {
65 $query->whereBetween('sessions.created_at', $this->get_current_period_iso_range());
66 })->when(\is_int($this->solo_record_id), function (Builder $query) {
67 $query->where('device_oss.device_os_id', '=', $this->solo_record_id);
68 })->groupBy('device_oss.device_os_id')->having('views', '>', 0)->tap(fn(Builder $query) => $this->apply_record_filters($query))->when($this->can_order_and_limit_at_record_level(), function (Builder $query) {
69 $query->tap(fn(Builder $query) => $this->apply_order_and_limit($query, $this->sort_configuration->column()));
70 });
71 $previous_period_query = Illuminate_Builder::new();
72 $previous_period_query->select(['sessions.device_os_id'])->selectRaw('SUM(sessions.total_views) AS previous_period_views')->selectRaw('COUNT(DISTINCT sessions.visitor_id) AS previous_period_visitors')->from($sessions_table, 'sessions')->whereBetween('sessions.created_at', $this->get_previous_period_iso_range())->groupBy('sessions.device_os_id');
73 $outer_query = Illuminate_Builder::new();
74 $outer_query->selectRaw('device_oss.*')->selectRaw('IF(sessions = 0, 0, views / sessions) AS views_per_session')->selectRaw('IFNULL((views - previous_period_views) / previous_period_views * 100, 0) AS views_growth')->selectRaw('IFNULL((visitors - previous_period_visitors) / previous_period_visitors * 100, 0) AS visitors_growth')->selectRaw('IFNULL(bounces / sessions * 100, 0) AS bounce_rate')->selectRaw('ROUND(CAST(wc_gross_sales - wc_refunded_amount AS SIGNED)) AS wc_net_sales')->selectRaw('IF(visitors = 0, 0, (wc_orders / visitors) * 100) AS wc_conversion_rate')->selectRaw('IF(visitors = 0, 0, (wc_gross_sales - wc_refunded_amount) / visitors) AS wc_earnings_per_visitor')->selectRaw('IF(wc_orders = 0, 0, ROUND(CAST(wc_gross_sales / wc_orders AS SIGNED))) AS wc_average_order_volume')->selectRaw('IF(visitors = 0, 0, (form_submissions / visitors) * 100) AS form_conversion_rate')->tap(function (Builder $query) {
75 foreach (Form::get_forms() as $form) {
76 $query->selectRaw("IF(visitors = 0, 0, ({$form->submissions_column()} / visitors) * 100) AS {$form->conversion_rate_column()}");
77 }
78 })->fromSub($device_oss_query, 'device_oss')->leftJoinSub($previous_period_query, 'previous_period_stats', 'device_oss.device_os_id', '=', 'previous_period_stats.device_os_id')->tap(fn(Builder $query) => $this->apply_aggregate_filters($query))->when(!$this->can_order_and_limit_at_record_level() && !($this->using_logical_or_operator() && $this->filtering_by_mixed_columns()), function (Builder $query) {
79 $query->tap(fn(Builder $query) => $this->apply_order_and_limit($query, $this->sort_configuration->column()));
80 });
81 if ($this->using_logical_or_operator() && $this->filtering_by_mixed_columns()) {
82 $og_outer_query = $outer_query;
83 $outer_query = Illuminate_Builder::new()->select('*')->fromSub($og_outer_query, 'records')->tap(fn(Builder $query) => $this->apply_or_filters($query))->tap(fn(Builder $query) => $this->apply_order_and_limit($query, $this->sort_configuration->column()));
84 }
85 return $outer_query;
86 }
87 }
88