PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / 2.3.0
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF v2.3.0
2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.9 2.2.8 trunk 1.10 1.3.3 1.3.4 1.3.5 1.3.5.1 1.3.5.2 1.3.6 1.3.6.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.5 All 103 releases
imagify / classes / Tracking / BaseTracking.php

BaseTracking.php in Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF 2.3.0, at classes/Tracking/BaseTracking.php

74 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 declare(strict_types=1);
3
4 namespace Imagify\Tracking;
5
6 use Imagify\Dependencies\WPMedia\Mixpanel\Optin;
7 use Imagify\Dependencies\WPMedia\Mixpanel\TrackingPlugin;
8
9 /**
10 * Abstract base class for Imagify tracking.
11 *
12 * @since 2.3.0
13 */
14 abstract class BaseTracking {
15
16 /**
17 * The Mixpanel opt-in service.
18 *
19 * @var Optin
20 */
21 protected $optin;
22
23 /**
24 * The Mixpanel tracking plugin service.
25 *
26 * @var TrackingPlugin
27 */
28 protected $mixpanel;
29
30 /**
31 * Constructor.
32 *
33 * @param Optin $optin The Mixpanel opt-in service.
34 * @param TrackingPlugin $mixpanel The Mixpanel tracking plugin service.
35 */
36 public function __construct( Optin $optin, TrackingPlugin $mixpanel ) {
37 $this->optin = $optin;
38 $this->mixpanel = $mixpanel;
39 }
40
41 /**
42 * Check if tracking is allowed.
43 *
44 * @return bool True if tracking is allowed, false otherwise.
45 */
46 public function can_track(): bool {
47 return $this->optin->can_track();
48 }
49
50 /**
51 * Returns the default event properties shared by every tracked event.
52 *
53 * IMPORTANT: do NOT add `domain`, `wp_version`, `php_version`, `plugin`,
54 * `brand`, or `application` here. `TrackingPlugin::track_direct()` injects
55 * those automatically and any value set here is silently overwritten.
56 *
57 * @return array<string, mixed>
58 */
59 protected function get_default_event_properties(): array {
60 $user = get_imagify_user();
61 $license_owner = '';
62
63 if ( ! is_wp_error( $user ) && ! empty( $user->email ) ) {
64 $license_owner = hash( 'sha256', $user->email );
65 }
66
67 return [
68 'context' => 'wp_plugin',
69 'license_owner' => $license_owner,
70 'user_id' => (int) get_current_user_id(),
71 ];
72 }
73 }
74