Campaign.php
10 months ago
Campaign_Landing_Page.php
9 months ago
Campaign_UTM_Campaign.php
9 months ago
Campaign_UTM_Medium.php
9 months ago
Campaign_UTM_Source.php
9 months ago
ClickWhale_Link_Page.php
1 year ago
Current_Traffic.php
2 years ago
Device.php
10 months ago
Form.php
1 year ago
Geo.php
10 months ago
Journey.php
5 months ago
Link.php
8 months ago
Link_Pattern.php
10 months ago
Model.php
6 months ago
Page.php
10 months ago
Page_Author_Archive.php
2 years ago
Page_Date_Archive.php
2 years ago
Page_Home.php
2 years ago
Page_Not_Found.php
1 year ago
Page_Post_Type_Archive.php
1 year ago
Page_Search.php
2 years ago
Page_Singular.php
1 year ago
Page_Term_Archive.php
2 years ago
Page_Virtual.php
1 year ago
Referrer.php
6 months ago
Referrer_Type.php
9 months ago
Universal_Model_Columns.php
1 year ago
Visitor.php
9 months ago
Universal_Model_Columns.php
163 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP\Models; |
| 4 | |
| 5 | use IAWPSCOPED\Illuminate\Support\Str; |
| 6 | /** @internal */ |
| 7 | trait Universal_Model_Columns |
| 8 | { |
| 9 | /** |
| 10 | * Handle dynamic column names such as those for form tracking |
| 11 | */ |
| 12 | public function __call($name, $arguments) |
| 13 | { |
| 14 | if (Str::startsWith($name, 'form_submissions_for_')) { |
| 15 | return $this->as_int($name); |
| 16 | } elseif (Str::startsWith($name, 'form_conversion_rate_for_')) { |
| 17 | return $this->as_float($name); |
| 18 | } |
| 19 | } |
| 20 | public function form_submissions() : int |
| 21 | { |
| 22 | return $this->as_int('form_submissions'); |
| 23 | } |
| 24 | public function form_conversion_rate() : float |
| 25 | { |
| 26 | return $this->as_float('form_conversion_rate'); |
| 27 | } |
| 28 | public function wc_orders() : float |
| 29 | { |
| 30 | return $this->as_float('wc_orders'); |
| 31 | } |
| 32 | public function wc_gross_sales() : float |
| 33 | { |
| 34 | return $this->as_float('wc_gross_sales'); |
| 35 | } |
| 36 | public function wc_refunds() : float |
| 37 | { |
| 38 | return $this->as_float('wc_refunds'); |
| 39 | } |
| 40 | public function wc_refunded_amount() : float |
| 41 | { |
| 42 | return $this->as_float('wc_refunded_amount'); |
| 43 | } |
| 44 | public function wc_net_sales() : float |
| 45 | { |
| 46 | return $this->as_float('wc_net_sales'); |
| 47 | } |
| 48 | public function wc_conversion_rate() : float |
| 49 | { |
| 50 | return $this->as_float('wc_conversion_rate'); |
| 51 | } |
| 52 | public function wc_earnings_per_visitor() : float |
| 53 | { |
| 54 | return $this->as_float('wc_earnings_per_visitor'); |
| 55 | } |
| 56 | public function wc_average_order_volume() : float |
| 57 | { |
| 58 | return $this->as_float('wc_average_order_volume'); |
| 59 | } |
| 60 | public function views() : int |
| 61 | { |
| 62 | return $this->as_int('views'); |
| 63 | } |
| 64 | public function previous_period_views() : int |
| 65 | { |
| 66 | return $this->as_int('previous_period_views'); |
| 67 | } |
| 68 | public function views_growth() : float |
| 69 | { |
| 70 | return $this->as_float('views_growth'); |
| 71 | } |
| 72 | public function views_per_session() : float |
| 73 | { |
| 74 | return $this->as_float('views_per_session'); |
| 75 | } |
| 76 | public function visitors() : int |
| 77 | { |
| 78 | return $this->as_int('visitors'); |
| 79 | } |
| 80 | public function previous_period_visitors() : int |
| 81 | { |
| 82 | return $this->as_int('previous_period_views'); |
| 83 | } |
| 84 | public function visitors_growth() : float |
| 85 | { |
| 86 | return $this->as_float('visitors_growth'); |
| 87 | } |
| 88 | public function clicks() : float |
| 89 | { |
| 90 | return $this->as_int('clicks'); |
| 91 | } |
| 92 | public function average_session_duration() : ?int |
| 93 | { |
| 94 | return $this->as_int('average_session_duration', null); |
| 95 | } |
| 96 | public function average_session_duration_growth() : float |
| 97 | { |
| 98 | $current = $this->average_session_duration(); |
| 99 | $previous = $this->previous_period_average_session_duration(); |
| 100 | if ($current == 0 || $previous == 0) { |
| 101 | return 0; |
| 102 | } else { |
| 103 | return ($current - $previous) / $previous * 100; |
| 104 | } |
| 105 | } |
| 106 | public function average_view_duration() : ?int |
| 107 | { |
| 108 | return $this->as_int('average_view_duration', null); |
| 109 | } |
| 110 | public function average_view_duration_growth() : float |
| 111 | { |
| 112 | $current = $this->average_view_duration(); |
| 113 | $previous = $this->previous_period_average_view_duration(); |
| 114 | if ($current == 0 || $previous == 0) { |
| 115 | return 0; |
| 116 | } else { |
| 117 | return ($current - $previous) / $previous * 100; |
| 118 | } |
| 119 | } |
| 120 | public function sessions() : int |
| 121 | { |
| 122 | return $this->as_int('sessions'); |
| 123 | } |
| 124 | public function previous_period_sessions() : int |
| 125 | { |
| 126 | return $this->as_int('previous_period_sessions'); |
| 127 | } |
| 128 | public function sessions_growth() : float |
| 129 | { |
| 130 | $current = $this->sessions(); |
| 131 | $previous = $this->previous_period_sessions(); |
| 132 | if ($current == 0 || $previous == 0) { |
| 133 | return 0; |
| 134 | } else { |
| 135 | return ($current - $previous) / $previous * 100; |
| 136 | } |
| 137 | } |
| 138 | public function previous_period_average_session_duration() : int |
| 139 | { |
| 140 | return $this->as_int('previous_period_average_session_duration'); |
| 141 | } |
| 142 | public function previous_period_average_view_duration() : int |
| 143 | { |
| 144 | return $this->as_int('previous_period_average_view_duration'); |
| 145 | } |
| 146 | public function bounces() : int |
| 147 | { |
| 148 | return $this->as_int('bounces'); |
| 149 | } |
| 150 | public function bounce_rate() : float |
| 151 | { |
| 152 | return $this->as_float('bounce_rate'); |
| 153 | } |
| 154 | private function as_float($property, $default = 0) : ?float |
| 155 | { |
| 156 | return \property_exists($this->row, $property) && $this->row->{$property} !== null ? \floatval($this->row->{$property}) : $default; |
| 157 | } |
| 158 | private function as_int($property, $default = 0) : ?int |
| 159 | { |
| 160 | return \property_exists($this->row, $property) && $this->row->{$property} !== null ? \intval($this->row->{$property}) : $default; |
| 161 | } |
| 162 | } |
| 163 |