| @@ -51,8 +51,17 @@ | ||
| 51 | 51 | */ |
| 52 | 52 | protected static $trackdata; |
| 53 | 53 | |
| 54 | 54 | /** |
| 55 | + * Optional associative array of extra information. | |
| 56 | + * | |
| 57 | + * @var array | |
| 58 | + * | |
| 59 | + * @since 1.16.7 (J) - 1.6.7 (WP) | |
| 60 | + */ | |
| 61 | + protected static $extra_info = []; | |
| 62 | + | |
| 63 | + /** | |
| 55 | 64 | * The tracking info identifier. |
| 56 | 65 | * |
| 57 | 66 | * @var int |
| 58 | 67 | */ |
| @@ -144,8 +153,13 @@ | ||
| 144 | 153 | // return the current fingerprint |
| 145 | 154 | return static::$fingerprint; |
| 146 | 155 | } |
| 147 | 156 | |
| 157 | + // abort if tracking is disabled | |
| 158 | + if (!VBOFactory::getConfig()->getBool('trkenabled')) { | |
| 159 | + return ''; | |
| 160 | + } | |
| 161 | + | |
| 148 | 162 | /** |
| 149 | 163 | * To check for an existing or previous fingerprint, we give the highest priority |
| 150 | 164 | * to the reserved request var "vbo_tracking", which may have been passed after |
| 151 | 165 | * a previous tracking session for a booking link with VCM. |
| @@ -919,8 +933,39 @@ | ||
| 919 | 933 | return static::$trackdata; |
| 920 | 934 | } |
| 921 | 935 | |
| 922 | 936 | /** |
| 937 | + * Returns a registry or array for the current extra information. | |
| 938 | + * | |
| 939 | + * @param bool $registry whether to get the registry object or array. | |
| 940 | + * | |
| 941 | + * @return JObject|array | |
| 942 | + * | |
| 943 | + * @since 1.16.7 (J) - 1.6.7 (WP) | |
| 944 | + */ | |
| 945 | + public function getExtraInfo($registry = true) | |
| 946 | + { | |
| 947 | + return $registry ? (new JObject(static::$extra_info)) : static::$extra_info; | |
| 948 | + } | |
| 949 | + | |
| 950 | + /** | |
| 951 | + * Sets a value for an extra information type. | |
| 952 | + * | |
| 953 | + * @param string $key the information key in the associative array. | |
| 954 | + * @param mixed $value the value to set for the given key. | |
| 955 | + * | |
| 956 | + * @return self | |
| 957 | + * | |
| 958 | + * @since 1.16.7 (J) - 1.6.7 (WP) | |
| 959 | + */ | |
| 960 | + public function setExtraInfo($key, $value = null) | |
| 961 | + { | |
| 962 | + static::$extra_info[$key] = $value; | |
| 963 | + | |
| 964 | + return $this; | |
| 965 | + } | |
| 966 | + | |
| 967 | + /** | |
| 923 | 968 | * Runs when visiting the booking details page in case conversion must be triggered. |
| 924 | 969 | * |
| 925 | 970 | * @param array $booking the booking record for conversion. |
| 926 | 971 | * |
| @@ -931,8 +976,13 @@ | ||
| 931 | 976 | public function triggerBookingConversion(array $booking) |
| 932 | 977 | { |
| 933 | 978 | $fingerprint = $this->getFingerprint(); |
| 934 | 979 | |
| 980 | + if (!$fingerprint) { | |
| 981 | + // tracking may be disabled | |
| 982 | + return $this; | |
| 983 | + } | |
| 984 | + | |
| 935 | 985 | $q = $this->dbo->getQuery(true); |
| 936 | 986 | |
| 937 | 987 | $q->select($this->dbo->qn([ |
| 938 | 988 | 'i.id', |
| @@ -955,19 +1005,30 @@ | ||
| 955 | 1005 | |
| 956 | 1006 | $last_tracking_record = $this->dbo->loadObject(); |
| 957 | 1007 | |
| 958 | 1008 | if (!$last_tracking_record) { |
| 1009 | + // tracking must be enabled and functioning | |
| 959 | 1010 | return $this; |
| 960 | 1011 | } |
| 961 | 1012 | |
| 962 | 1013 | $prev_trackdata = json_decode($last_tracking_record->trkdata); |
| 963 | 1014 | if (!is_object($prev_trackdata)) { |
| 1015 | + // no previous tracking data available | |
| 964 | 1016 | return $this; |
| 965 | 1017 | } |
| 966 | 1018 | |
| 967 | - if (!isset($prev_trackdata->converted)) { | |
| 968 | - // make sure to set this value | |
| 969 | - $prev_trackdata->converted = 1; | |
| 1019 | + /** | |
| 1020 | + * Check if tracking was made for the current booking status. | |
| 1021 | + * | |
| 1022 | + * @since 1.16.7 (J) - 1.6.7 (WP) | |
| 1023 | + */ | |
| 1024 | + $converted_status_prop = 'converted_' . strtolower($booking['status']); | |
| 1025 | + | |
| 1026 | + if (!isset($prev_trackdata->{$converted_status_prop})) { | |
| 1027 | + // proceed with triggering the conversion event for this status | |
| 1028 | + | |
| 1029 | + // ensure no more tracking events will be triggered for the current status | |
| 1030 | + $prev_trackdata->{$converted_status_prop} = 1; | |
| 970 | 1031 | |
| 971 | 1032 | $upd_record = new stdClass; |
| 972 | 1033 | $upd_record->id = $last_tracking_record->id; |
| 973 | 1034 | $upd_record->trkdata = json_encode($prev_trackdata); |