Events
3 months ago
EngagementScore.php
6 months ago
JourneyStatisticsJob.php
5 months ago
Timeline.php
5 months ago
EngagementScore.php
43 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP\Journey; |
| 4 | |
| 5 | /** @internal */ |
| 6 | class EngagementScore |
| 7 | { |
| 8 | public static function for_session_total_views(int $views) : int |
| 9 | { |
| 10 | if ($views === 1) { |
| 11 | return 1; |
| 12 | } |
| 13 | $average_views_cutoff = self::get_int_option('iawp_average_views_cutoff', 3); |
| 14 | if ($views <= $average_views_cutoff) { |
| 15 | return 2; |
| 16 | } |
| 17 | return 3; |
| 18 | } |
| 19 | public static function for_session_duration(?int $duration_in_seconds) : int |
| 20 | { |
| 21 | $low_duration_cutoff = self::get_int_option('iawp_low_duration_cutoff', 10); |
| 22 | if ($duration_in_seconds <= $low_duration_cutoff) { |
| 23 | return 1; |
| 24 | } |
| 25 | $average_duration_cutoff = self::get_int_option('iawp_average_duration_cutoff', 60); |
| 26 | if ($duration_in_seconds <= $average_duration_cutoff) { |
| 27 | return 2; |
| 28 | } |
| 29 | return 3; |
| 30 | } |
| 31 | private static function get_int_option(string $option, int $default) : ?int |
| 32 | { |
| 33 | $value = \get_option($option, null); |
| 34 | if (\is_string($value) && \ctype_digit($value)) { |
| 35 | $value = \intval($value); |
| 36 | } |
| 37 | if (!\is_int($value)) { |
| 38 | return $default; |
| 39 | } |
| 40 | return $value; |
| 41 | } |
| 42 | } |
| 43 |