class-event-grouped.php
4 years ago
class-event-single.php
1 year ago
class-event.php
4 years ago
class-events-automatic.php
4 years ago
class-events-custom.php
1 year ago
class-events-edd.php
1 year ago
class-events-fdp.php
4 years ago
class-events-woo.php
1 year ago
interface-events.php
1 year ago
class-events-automatic.php
166 lines
| 1 | <?php |
| 2 | namespace PixelYourSite; |
| 3 | |
| 4 | /* |
| 5 | * Automatic Events we will fire this event in order to capture all actions like clicks, video |
| 6 | views, downloads, comments, forms. |
| 7 | * */ |
| 8 | |
| 9 | class EventsAutomatic extends EventsFactory { |
| 10 | private static $_instance; |
| 11 | |
| 12 | private $events = array( |
| 13 | 'automatic_event_form' , |
| 14 | 'automatic_event_signup' , |
| 15 | 'automatic_event_login' , |
| 16 | 'automatic_event_download' , |
| 17 | 'automatic_event_comment' , |
| 18 | |
| 19 | 'automatic_event_scroll' , |
| 20 | 'automatic_event_time_on_page' , |
| 21 | 'automatic_event_search' , |
| 22 | ); |
| 23 | |
| 24 | public static function instance() { |
| 25 | |
| 26 | if ( is_null( self::$_instance ) ) { |
| 27 | self::$_instance = new self(); |
| 28 | } |
| 29 | |
| 30 | return self::$_instance; |
| 31 | |
| 32 | } |
| 33 | |
| 34 | private function __construct() { |
| 35 | add_filter("pys_event_factory",[$this,"register"]); |
| 36 | } |
| 37 | |
| 38 | function register($list) { |
| 39 | $list[] = $this; |
| 40 | return $list; |
| 41 | } |
| 42 | |
| 43 | static function getSlug() { |
| 44 | return "automatic"; |
| 45 | } |
| 46 | |
| 47 | function getEvents() { |
| 48 | return $this->events; |
| 49 | } |
| 50 | |
| 51 | function getCount() { |
| 52 | $count = 0; |
| 53 | if($this->isEnabled()) { |
| 54 | foreach ($this->events as $event) { |
| 55 | if(PYS()->getOption($event."_enabled")) { |
| 56 | $count++; |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | return $count; |
| 61 | } |
| 62 | |
| 63 | |
| 64 | function isEnabled() { |
| 65 | return PYS()->getOption("automatic_events_enabled"); |
| 66 | } |
| 67 | |
| 68 | // return option for js part |
| 69 | function getOptions() { |
| 70 | return array( |
| 71 | |
| 72 | ); |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Check is event ready for fire |
| 77 | * @param $event |
| 78 | * @return bool |
| 79 | */ |
| 80 | function isReadyForFire($event) { |
| 81 | |
| 82 | if(!$this->isEnabled()) return false; |
| 83 | |
| 84 | if(!in_array($event,$this->events)) return false; |
| 85 | |
| 86 | switch($event) { |
| 87 | |
| 88 | case "automatic_event_login" : { |
| 89 | if($user_id = get_current_user_id()) { |
| 90 | if (get_user_meta($user_id, 'pys_just_login', true)) { |
| 91 | delete_user_meta($user_id, 'pys_just_login'); |
| 92 | return PYS()->getOption( $event."_enabled"); |
| 93 | } |
| 94 | } |
| 95 | return false; |
| 96 | } |
| 97 | case 'automatic_event_signup' : { |
| 98 | if ( $user_id = get_current_user_id() ) { |
| 99 | if ( get_user_meta( $user_id, 'pys_complete_registration', true ) ) { |
| 100 | return PYS()->getOption( $event."_enabled"); |
| 101 | } |
| 102 | } |
| 103 | return false; |
| 104 | } |
| 105 | case 'automatic_event_search' : { |
| 106 | return PYS()->getOption( $event."_enabled") && is_search(); |
| 107 | } |
| 108 | default: { |
| 109 | return PYS()->getOption( $event."_enabled"); |
| 110 | } |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * @param String $event |
| 116 | * @return SingleEvent |
| 117 | */ |
| 118 | function getEvent($event) { |
| 119 | $payload = []; |
| 120 | $params = []; |
| 121 | $item = new SingleEvent($event,EventTypes::$DYNAMIC,self::getSlug()); |
| 122 | switch ($event) { |
| 123 | |
| 124 | |
| 125 | case "automatic_event_form": { |
| 126 | $payload['name'] = 'Form'; |
| 127 | }break; |
| 128 | case "automatic_event_download": { |
| 129 | $payload['name'] = 'Download'; |
| 130 | $payload["extensions"] = PYS()->getOption( 'automatic_event_download_extensions' ); |
| 131 | }break; |
| 132 | case "automatic_event_comment": { |
| 133 | $payload['name'] = 'Comment'; |
| 134 | }break; |
| 135 | |
| 136 | case "automatic_event_scroll": { |
| 137 | $payload['name'] = 'PageScroll'; |
| 138 | $payload["scroll_percent"] = PYS()->getOption('automatic_event_scroll_value'); |
| 139 | }break; |
| 140 | case "automatic_event_time_on_page": { |
| 141 | $payload['name'] = 'TimeOnPage'; |
| 142 | $payload["time_on_page"] = PYS()->getOption('automatic_event_time_on_page_value'); |
| 143 | |
| 144 | }break; |
| 145 | case "automatic_event_search": |
| 146 | case "automatic_event_signup": |
| 147 | case "automatic_event_login": { |
| 148 | $item = new SingleEvent($event,EventTypes::$STATIC,self::getSlug()); |
| 149 | } break; |
| 150 | } |
| 151 | |
| 152 | $item->addParams($params); |
| 153 | $item->addPayload($payload); |
| 154 | return $item; |
| 155 | } |
| 156 | |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * @return EventsAutomatic |
| 161 | */ |
| 162 | function EventsAutomatic() { |
| 163 | return EventsAutomatic::instance(); |
| 164 | } |
| 165 | |
| 166 | EventsAutomatic(); |