• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wingify / vwo-php-sdk / 5551145046

pending completion
5551145046

push

github

rohitesh-wingify
refactor(events): fixed revenue value not passed error for data360 accounts

37 of 37 new or added lines in 3 files covered. (100.0%)

1895 of 2046 relevant lines covered (92.62%)

84.43 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.79
/src/VWO.php
1
<?php
2

3
/**
4
 * Copyright 2019-2022 Wingify Software Pvt. Ltd.
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *    http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18

19
namespace vwo;
20

21
use Exception as Exception;
22
use vwo\Constants\Constants as Constants;
23
use vwo\Constants\EventEnum;
24
use vwo\Constants\FileNameEnum;
25
use vwo\Constants\Urls;
26
use vwo\Constants\Urls as UrlConstants;
27
use vwo\Constants\CampaignTypes;
28
use vwo\Services\HooksManager;
29
use vwo\Services\UsageStats;
30
use vwo\Storage\UserStorageInterface;
31
use vwo\Utils\AccountUtil;
32
use vwo\Utils\Campaign as CampaignUtil;
33
use vwo\Utils\Common as CommonUtil;
34
use vwo\Utils\DataLocationManager;
35
use vwo\Utils\Validations as ValidationsUtil;
36
use vwo\Utils\ImpressionBuilder as ImpressionBuilder;
37
use vwo\Utils\EventDispatcher as EventDispatcher;
38
use Monolog\Logger as Logger;
39
use vwo\Logger\LoggerInterface;
40
use vwo\Services\LoggerService as LoggerService;
41
use vwo\Logger\VWOLogger as VWOLogger;
42
use vwo\Core\Bucketer as Bucketer;
43
use vwo\Core\VariationDecider as VariationDecider;
44
use vwo\Utils\LogMessagesUtil;
45

46
/***
47
 * Class for exposing various APIs
48
 */
49
class VWO
50
{
51
    /****
52
     * @var static variables for log levels
53
     */
54

55
    // Levels are as per monolog docs - https://github.com/Seldaek/monolog/blob/master/doc/01-usage.md#log-levels
56
    static $LOG_LEVEL_DEBUG = 100;
57
    static $LOG_LEVEL_INFO = 200;
58
    static $LOG_LEVEL_WARNINGG = 300;
59
    static $LOG_LEVEL_ERROR = 400;
60

61
    const CLASSNAME = FileNameEnum::VWO;
62

63
    static $apiName;
64

65
    static $_variationDecider;
66
    /**
67
     * @var mixed|string to save settings
68
     */
69
    var $settings = '';
70
    /**
71
     * @var Connection to save connection object for curl requests
72
     */
73
    // var $connection;
74
    /**
75
     * @var string to save userStorage interface object
76
     */
77

78
    var $_userStorageObj;
79
    /**
80
     * @var int to save if dev mode is enabled or not
81
     */
82
    var $isDevelopmentMode;
83

84
    private $goalTypeToTrack;
85

86
    private $isOptedOut = false;
87

88
    const GOAL_TYPES = [
89
        'REVENUE' => 'REVENUE_TRACKING',
90
        'CUSTOM' => 'CUSTOM_GOAL',
91
        'ALL' => 'ALL'
92
    ];
93

94
    /**
95
     * VWO constructor.
96
     *
97
     * @param  $config
98
     * @throws Exception
99
     */
100
    function __construct($config)
101
    {
102
        self::$apiName = 'init';
420✔
103
        LoggerService::setApiName(self::$apiName);
420✔
104
        if (!is_array($config)) {
420✔
105
            return (object)[];
6✔
106
        }
107

108
        if (!ValidationsUtil::validateSDKConfiguration($config, self::$apiName)) {
414✔
109
            LoggerService::log(Logger::ERROR, 'CONFIG_CORRUPTED', [], self::CLASSNAME);
×
110
            return (object)[];
×
111
        }
112
        LogMessagesUtil::instance();
414✔
113

114
        $usageStats = [];
414✔
115
        // is settings and logger files are provided then set the values to the object
116
        $settings = isset($config['settingsFile']) ? $config['settingsFile'] : '';
414✔
117
        $logger = isset($config['logging']) ? $config['logging'] : null;
414✔
118
        if ($settings) {
414✔
119
            DataLocationManager::instance()->setSettings($settings);
408✔
120
        }
68✔
121

122
        // dev mode enable wont send tracking hits to the servers
123
        $this->isDevelopmentMode = (isset($config['isDevelopmentMode']) && $config['isDevelopmentMode'] == 1) ? 1 : 0;
414✔
124

125
        $this->eventDispatcher = new EventDispatcher($this->isDevelopmentMode);
414✔
126

127
        if ($logger == null) {
414✔
128
            $_logger = new VWOLogger(Logger::DEBUG, 'php://stdout');
36✔
129

130
            LoggerService::setLogger($_logger);
36✔
131
        } elseif ($logger instanceof LoggerInterface) {
384✔
132
            LoggerService::setLogger($logger);
378✔
133
            LoggerService::log(Logger::DEBUG, 'CONFIG_CUSTOM_LOGGER_USED', [], self::CLASSNAME);
378✔
134
            $usageStats['cl'] = 1;
378✔
135
        }
63✔
136

137
        // user storage service
138
        if (isset($config['userStorageService']) && ($config['userStorageService'] instanceof UserStorageInterface)) {
414✔
139
            $this->_userStorageObj = $config['userStorageService'];
78✔
140
            $usageStats['ss'] = 1;
78✔
141
        } else {
13✔
142
            $this->_userStorageObj = '';
336✔
143
        }
144

145
        if (isset($config['goalTypeToTrack'])) {
414✔
146
            if (array_key_exists($config['goalTypeToTrack'], self::GOAL_TYPES)) {
24✔
147
                $this->goalTypeToTrack = $config['goalTypeToTrack'];
24✔
148
                $usageStats['gt'] = 1;
24✔
149
            } else {
4✔
150
                LoggerService::log(Logger::ERROR, 'CONFIG_PARAMETER_INVALID', ['{parameter}' => 'goalTypeToTrack', '{api}' => self::$apiName, '{type}' => 'strings(REVENUE, CUSTOM, ALL)'], self::CLASSNAME);
20✔
151
            }
152
        } else {
4✔
153
            $this->goalTypeToTrack = 'ALL';
396✔
154
        }
155

156
        // initial logging started for each new object
157
        if ($this->isDevelopmentMode) {
414✔
158
            LoggerService::log(
192✔
159
                Logger::DEBUG,
192✔
160
                'CONFIG_DEVELOPMENT_MODE_STATUS',
192✔
161
                [],
192✔
162
                self::CLASSNAME
160✔
163
            );
32✔
164
        }
32✔
165

166
        $res = ValidationsUtil::checkSettingSchema($settings);
414✔
167
        if ($res) {
414✔
168
            $this->settings = CampaignUtil::makeRanges($settings);
402✔
169
            LoggerService::log(
402✔
170
                Logger::DEBUG,
402✔
171
                'SETTINGS_FILE_PROCESSED',
402✔
172
                ['{accountId}' => $this->settings['accountId']],
402✔
173
                self::CLASSNAME
335✔
174
            );
67✔
175
        } else {
67✔
176
            LoggerService::log(Logger::ERROR, 'SETTINGS_FILE_INVALID', [], self::CLASSNAME);
12✔
177
            return (object)[];
12✔
178
        }
179

180
        // $this->connection = new Connection();
181
        LoggerService::log(Logger::INFO, 'SDK_INITIALIZED', [], self::CLASSNAME);
402✔
182

183
        $this->variationDecider = new VariationDecider($this->settings);
402✔
184
        if (isset($this->settings['accountId'])) {
402✔
185
            $this->variationDecider->setAccountId($this->settings['accountId']);
402✔
186
            $accountUtil = AccountUtil::instance();
402✔
187
            $accountUtil->setAccountId($this->settings['accountId']);
402✔
188
        }
67✔
189
        // Initialize Hooks manager so that callbacks can be invoked
190
        $this->variationDecider->setHooksManager(new HooksManager($config));
402✔
191

192
        $this->usageStats = new UsageStats($usageStats, $config, $this->isDevelopmentMode);
402✔
193
        return $this;
402✔
194
    }
195

196
    /**
197
     * @param  String|Integer $accountId
198
     * @param  String         $sdkKey
199
     * @param  bool           $isTriggeredByWebhook
200
     * @return bool|mixed
201
     */
202
    public static function getSettingsFile($accountId, $sdkKey, $isTriggeredByWebhook = false)
203
    {
204
        self::$apiName = 'getSettingsFile';
12✔
205
        LoggerService::setApiName(self::$apiName);
12✔
206
        if (!$accountId || !$sdkKey) {
12✔
207
            LoggerService::log(Logger::ERROR, 'MISSING_IMPORT_SETTINGS_MANDATORY_PARAMS', [], self::CLASSNAME);
×
208
            return false;
1✔
209
        }
210
        try {
1✔
211
            $parameters = ImpressionBuilder::getSettingsFileQueryParams($accountId, $sdkKey);
12✔
212
            $eventDispatcher = new EventDispatcher(false);
12✔
213

214
            if ($isTriggeredByWebhook) {
12✔
215
                $url = UrlConstants::WEBHOOK_SETTINGS_URL;
6✔
216
            } else {
1✔
217
                $url = UrlConstants::SETTINGS_URL;
6✔
218
            }
219

220
            return $eventDispatcher->send($url, $parameters);
12✔
221
        } catch (Exception $e) {
×
222
            LoggerService::log(Logger::ERROR, $e->getMessage(), [], self::CLASSNAME);
×
223
        }
224
        return false;
×
225
    }
226

227
    /**
228
     * @param  $campaignKey
229
     * @param  $userId
230
     * @param  $options
231
     * @return bool|null
232
     */
233
    public function isFeatureEnabled($campaignKey, $userId, $options = [])
234
    {
235
        self::$apiName = 'isFeatureEnabled';
90✔
236
        LoggerService::setApiName(self::$apiName);
90✔
237

238
        if ($this->isOptedOut()) {
90✔
239
            return false;
6✔
240
        }
241

242
        try {
243
            if (!ValidationsUtil::validateIsFeatureEnabledParams($campaignKey, $userId, self::$apiName)) {
84✔
244
                LoggerService::log(Logger::ERROR, 'API_BAD_PARAMETERS', ['{api}' => self::$apiName], self::CLASSNAME);
6✔
245
                return null;
6✔
246
            }
247
            // get campaigns
248
            $campaign = ValidationsUtil::getCampaignFromCampaignKey($campaignKey, $this->settings, self::$apiName);
84✔
249
            if ($campaign == null) {
84✔
250
                return null;
12✔
251
            }
252
            if ($campaign['type'] == CampaignTypes::AB) {
78✔
253
                LoggerService::log(
12✔
254
                    Logger::WARNING,
12✔
255
                    'CAMPAIGN_NOT_RUNNING',
12✔
256
                    ['{api}' => 'isFeatureEnabled', '{campaignKey}' => $campaignKey, '{userId}' => $userId],
12✔
257
                    self::CLASSNAME
10✔
258
                );
2✔
259
                return null;
12✔
260
            }
261

262
            $result['response'] = false;
78✔
263
            $variationData = $this->variationDecider->fetchVariationData($this->_userStorageObj, $campaign, $userId, $options, self::$apiName);
79✔
264
            // below condition says that if bucket is there and isFeatureEnabled is not present it means it will be feature rollout type campaign and return true
265
            // if isFeatureEnabled is there and it must be true then result is true
266
            // else return to false
267
            $result['response'] = ((isset($variationData) && !isset($variationData['isFeatureEnabled'])) || (isset($variationData['isFeatureEnabled']) && $variationData['isFeatureEnabled']) == true) ? true : false;
78✔
268

269
            if ($variationData) {
78✔
270
                if ($this->isEventArchEnabled()) {
60✔
271
                    $parameters = ImpressionBuilder::getEventsBaseProperties($this->settings['accountId'], $this->getSDKKey(), EventEnum::VWO_VARIATION_SHOWN, $this->usageStats->getUsageStats());
6✔
272
                    $payload = ImpressionBuilder::getTrackUserPayloadData(
6✔
273
                        $this->settings,
6✔
274
                        $userId,
4✔
275
                        EventEnum::VWO_VARIATION_SHOWN,
6✔
276
                        $campaign['id'],
6✔
277
                        $variationData['id']
6✔
278
                    );
1✔
279
                } else {
1✔
280
                    $parameters = ImpressionBuilder::getVisitorQueryParams(
54✔
281
                        $this->settings['accountId'],
54✔
282
                        $campaign,
36✔
283
                        $userId,
36✔
284
                        $variationData['id'],
54✔
285
                        $this->getSDKKey()
54✔
286
                    );
9✔
287
                    $parameters = array_merge($parameters, $this->usageStats->getUsageStats());
54✔
288
                }
289
            }
10✔
290

291
            if (isset($variationData) && $result['response'] == false) {
78✔
292
                if ($this->isEligibleToSendImpressionToVWO()) {
22✔
293
                    if ($this->isEventArchEnabled()) {
22✔
294
                        $response = $this->eventDispatcher->sendEventRequest($parameters, $payload);
6✔
295
                    } else {
1✔
296
                        LoggerService::log(
16✔
297
                            Logger::DEBUG,
16✔
298
                            'IMPRESSION_FOR_TRACK_USER',
16✔
299
                            ['{properties}' => $this->getAllowedToLogImpressionParams($parameters)],
16✔
300
                            self::CLASSNAME
14✔
301
                        );
2✔
302
                        $response = $this->eventDispatcher->sendAsyncRequest(CommonUtil::getUrl(Urls::TRACK_USER_ENDPOINT), 'GET', $parameters);
16✔
303
                    }
304
                    LoggerService::log(
22✔
305
                        Logger::INFO,
22✔
306
                        'FEATURE_STATUS',
22✔
307
                        ['{campaignKey}' => $campaignKey, '{userId}' => $userId, '{status}' => 'disabled'],
22✔
308
                        self::CLASSNAME
19✔
309
                    );
3✔
310
                    if ($response) {
22✔
311
                        LoggerService::log(
10✔
312
                            Logger::INFO,
10✔
313
                            'IMPRESSION_SUCCESS',
10✔
314
                            [
315
                                '{endPoint}' => 'track-user',
10✔
316
                                '{mainKeys}' => json_encode(["campaignId" => $campaign['id']]),
10✔
317
                                '{accountId}' => $this->settings['accountId']
10✔
318
                            ],
1✔
319
                            self::CLASSNAME
19✔
320
                        );
1✔
321
                    }
1✔
322
                } else {
3✔
323
                    LoggerService::log(
×
324
                        Logger::INFO,
×
325
                        'CAMPAIGN_USER_ALREADY_TRACKED',
×
326
                        ['{userId}' => $userId, '{campaignKey}' => $campaignKey, '{api}' => self::$apiName],
×
327
                        self::CLASSNAME
328
                    );
329
                }
330
                return false;
22✔
331
            }
332
            if ($result !== false && isset($result['response']) && $result['response'] == true && isset($variationData)) {
74✔
333
                if ($this->isEligibleToSendImpressionToVWO()) {
56✔
334
                    if ($this->isEventArchEnabled()) {
56✔
335
                        $response = $this->eventDispatcher->sendEventRequest($parameters, $payload);
6✔
336
                    } else {
1✔
337
                        LoggerService::log(
50✔
338
                            Logger::DEBUG,
50✔
339
                            'IMPRESSION_FOR_TRACK_USER',
50✔
340
                            ['{properties}' => $this->getAllowedToLogImpressionParams($parameters)],
50✔
341
                            self::CLASSNAME
41✔
342
                        );
9✔
343
                        $response = $this->eventDispatcher->sendAsyncRequest(CommonUtil::getUrl(Urls::TRACK_USER_ENDPOINT), 'GET', $parameters);
50✔
344
                    }
345
                    LoggerService::log(
56✔
346
                        Logger::INFO,
56✔
347
                        'FEATURE_STATUS',
56✔
348
                        ['{campaignKey}' => $campaignKey, '{userId}' => $userId, '{status}' => 'enabled'],
56✔
349
                        self::CLASSNAME
46✔
350
                    );
10✔
351

352
                    if ($response) {
56✔
353
                        LoggerService::log(
32✔
354
                            Logger::INFO,
32✔
355
                            'IMPRESSION_SUCCESS',
32✔
356
                            [
357
                                '{mainKeys}' => json_encode(["campaignId" => $campaign['id']]),
32✔
358
                                '{endPoint}' => Urls::TRACK_USER_ENDPOINT,
32✔
359
                                '{campaignId}' => $campaign['id'],
32✔
360
                                '{accountId}' => $this->settings['accountId']
32✔
361
                            ],
6✔
362
                            self::CLASSNAME
46✔
363
                        );
6✔
364
                    }
6✔
365
                } else {
10✔
366
                    LoggerService::log(
×
367
                        Logger::INFO,
×
368
                        'CAMPAIGN_USER_ALREADY_TRACKED',
×
369
                        ['{userId}' => $userId, '{campaignKey}' => $campaignKey, '{api}' => self::$apiName],
×
370
                        self::CLASSNAME
371
                    );
372
                }
373
                return true;
56✔
374
            }
375
            return $campaign['type'] == CampaignTypes::FEATURE_ROLLOUT ? false : null;
30✔
376
        } catch (Exception $e) {
6✔
377
            LoggerService::log(Logger::ERROR, $e->getMessage(), [], self::CLASSNAME);
6✔
378
        }
379

380
        return isset($campaign) && isset($campaign['type']) && ($campaign['type'] == CampaignTypes::FEATURE_ROLLOUT) ? false : null;
6✔
381
    }
382

383
    /**
384
     * @param  $campaignKey
385
     * @param  $variableKey
386
     * @param  $userId
387
     * @return bool|float|int|null|string
388
     */
389
    public function getFeatureVariableValue($campaignKey, $variableKey, $userId, $options = [])
390
    {
391
        self::$apiName = 'getFeatureVariableValue';
90✔
392
        LoggerService::setApiName(self::$apiName);
90✔
393

394
        if ($this->isOptedOut()) {
90✔
395
            return false;
6✔
396
        }
397

398
        try {
399
            if (!ValidationsUtil::validateIsFeatureEnabledParams($campaignKey, $userId, self::$apiName)) {
84✔
400
                LoggerService::log(Logger::ERROR, 'API_BAD_PARAMETERS', ['{api}' => self::$apiName], self::CLASSNAME);
6✔
401
                return null;
6✔
402
            }
403

404
            $campaign = ValidationsUtil::getCampaignFromCampaignKey($campaignKey, $this->settings, self::$apiName);
84✔
405
            if ($campaign != null && $campaign['type'] == CampaignTypes::AB) {
84✔
406
                LoggerService::log(
6✔
407
                    Logger::ERROR,
6✔
408
                    'API_NOT_APPLICABLE',
6✔
409
                    [
410
                        '{api}' => 'getFeatureVariableValue',
6✔
411
                        '{userId}' => $userId,
6✔
412
                        '{campaignKey}' => $campaignKey,
6✔
413
                        '{campaignType}' => 'SERVER AB'
5✔
414
                    ],
1✔
415
                    self::CLASSNAME
5✔
416
                );
1✔
417
                return null;
6✔
418
            }
419
            $value = null;
78✔
420

421
            $featureData['response'] = false;
78✔
422
            $variationData = $this->variationDecider->fetchVariationData($this->_userStorageObj, $campaign, $userId, $options, self::$apiName);
78✔
423
            $featureData['variationData'] = $variationData;
72✔
424
            // below condition says that if bucket is there and isFeatureEnabled is not present it means it will be feature rollout type campaign and return true
425
            // if isFeatureEnabled is there and it must be true then result is true
426
            // else return to false
427
            $featureData['response'] = ((isset($variationData) && !isset($variationData['isFeatureEnabled'])) || (isset($variationData['isFeatureEnabled']) && $variationData['isFeatureEnabled']) == true) ? true : false;
72✔
428

429
            if ($featureData) {
72✔
430
                if (isset($featureData['variationData'])) {
72✔
431
                    if ($campaign['type'] == CampaignTypes::FEATURE_ROLLOUT) {
54✔
432
                        $featureVariable = $campaign['variables'];
36✔
433
                    } else {
6✔
434
                        // it is part of feature test
435
                        if ($featureData['response'] == 1 && isset($featureData['variationData']['variables'])) {
18✔
436
                            $featureVariable = $featureData['variationData']['variables'];
18✔
437
                        } else {
3✔
438
                            $featureVariable = CommonUtil::fetchControlVariation(
6✔
439
                                $campaign['variations']
6✔
440
                            )['variables'];
6✔
441
                        }
442
                    }
443
                    $value = CommonUtil::getVariableValue($featureVariable, $variableKey);
54✔
444
                }
9✔
445
            }
12✔
446
            if ($value == null) {
72✔
447
                LoggerService::log(
30✔
448
                    Logger::INFO,
30✔
449
                    'FEATURE_VARIABLE_DEFAULT_VALUE',
30✔
450
                    [
451
                        '{variableKey}' => $variableKey,
30✔
452
                        '{variationName}' => $variationData["name"]
30✔
453
                    ],
5✔
454
                    self::CLASSNAME
21✔
455
                );
5✔
456
            } else {
5✔
457
                if (is_array($value)) {
54✔
458
                    $value = json_encode($value);
×
459
                }
460
                LoggerService::log(
54✔
461
                    Logger::INFO,
54✔
462
                    'FEATURE_VARIABLE_VALUE',
54✔
463
                    [
464
                        '{userId}' => $userId,
54✔
465
                        '{variableKey}' => $variableKey,
54✔
466
                        '{campaignKey}' => $campaignKey,
54✔
467
                        '{variableValue}' => $value
45✔
468
                    ],
9✔
469
                    self::CLASSNAME
45✔
470
                );
9✔
471
            }
472

473
            return $value;
69✔
474
        } catch (Exception $e) {
10✔
475
            LoggerService::log(Logger::ERROR, $e->getMessage(), [], self::CLASSNAME);
10✔
476
        }
477

478
        return null;
10✔
479
    }
480

481
    /**
482
     * API for track the user goals and revenueValue
483
     *
484
     * @param  string $campaignKey
485
     * @param  string $userId
486
     * @param  string $goalIdentifier
487
     * @param  array  $options
488
     * @return array|bool|null
489
     */
490
    public function track($campaignKey = '', $userId = '', $goalIdentifier = '', array $options = [])
491
    {
492
        self::$apiName = 'track';
156✔
493
        LoggerService::setApiName(self::$apiName);
156✔
494

495
        if ($this->isOptedOut()) {
156✔
496
            return false;
12✔
497
        }
498

499
        $revenueValue = CommonUtil::getValueFromOptions($options, 'revenueValue');
144✔
500
        $bucketInfo = null;
144✔
501

502
        if (
503
            empty($userId)
144✔
504
            || empty($goalIdentifier)
120✔
505
            || !(is_null($campaignKey) || is_array($campaignKey) || is_string($campaignKey))
144✔
506
        ) {
24✔
507
            LoggerService::log(Logger::ERROR, 'API_BAD_PARAMETERS', ['{api}' => self::$apiName], self::CLASSNAME);
6✔
508
            return null;
6✔
509
        }
510

511
        $goalTypeToTrack = $this->getGoalTypeToTrack($options);
144✔
512
        $campaigns = ValidationsUtil::getCampaigns($campaignKey, $this->settings, $goalIdentifier, $goalTypeToTrack, self::$apiName);
144✔
513

514
        if (empty($campaigns)) {
144✔
515
            return null;
30✔
516
        }
517

518
        $metricMap = [];
132✔
519
        $revenueProps = [];
132✔
520
        $result = [];
132✔
521
        $batchEventData = [];
132✔
522
        $eventProperties = CommonUtil::getValueFromOptions($options, 'eventProperties');
132✔
523

524
        if (!$eventProperties) {
132✔
525
            $eventProperties = [];
120✔
526
        }
20✔
527

528
        foreach ($campaigns as $campaign) {
132✔
529
            try {
530
                if ($campaign['type'] == CampaignTypes::FEATURE_ROLLOUT) {
132✔
531
                    LoggerService::log(
6✔
532
                        Logger::ERROR,
6✔
533
                        'API_NOT_APPLICABLE',
6✔
534
                        [
535
                            '{api}' => 'track',
6✔
536
                            '{userId}' => $userId,
6✔
537
                            '{campaignKey}' => $campaign['key'],
6✔
538
                            '{campaignType}' => $campaign['type']
6✔
539
                        ],
1✔
540
                        self::CLASSNAME
5✔
541
                    );
1✔
542
                    $result[$campaign['key']] = null;
6✔
543
                    continue;
6✔
544
                }
545

546
                $bucketInfo = $this->variationDecider->fetchVariationData($this->_userStorageObj, $campaign, $userId, $options, self::$apiName, $goalIdentifier);
126✔
547
                if ($bucketInfo === null) {
120✔
548
                    $result[$campaign['key']] = null;
60✔
549
                    continue;
60✔
550
                }
551

552
                $goal = CommonUtil::getGoalFromGoals($campaign['goals'], $goalIdentifier);
96✔
553
                $goalId = isset($goal['id']) ? $goal['id'] : 0;
96✔
554
                $mca = isset($goal['mca']) ? $goal['mca'] : null;
96✔
555
                if ($goalId && isset($bucketInfo['id']) && $bucketInfo['id'] > 0) {
96✔
556
                    if ($goal['type'] == "REVENUE_TRACKING") {
96✔
557
                        if ($this->isEventArchEnabled()) {
42✔
558
                            if (!$revenueValue) {
30✔
559
                                $doesRevenuePropExist = false;
30✔
560

561
                                if (isset($goal['revenueProp'])) {
30✔
562
                                    $doesRevenuePropExist = true;
24✔
563
                                }
4✔
564

565
                                //If it's a metric of type - value of an event property and calculation logic is first Value (mca doesn't exist)
566
                                if (!isset($mca)) {
30✔
567
                                    /*
568
                                    In this case it is expected that goal will have revenueProp
569
                                    Error should be logged if eventProperties is not Defined ` OR ` eventProperties does not have revenueProp key
570
                                */
571
                                    if (!isset($eventProperties) || !array_key_exists($goal['revenueProp'], $eventProperties)) {
24✔
572
                                        LoggerService::log(
12✔
573
                                            Logger::ERROR,
12✔
574
                                            'TRACK_API_REVENUE_NOT_PASSED_FOR_REVENUE_GOAL',
12✔
575
                                            [
576
                                                '{goalIdentifier}' => $goalIdentifier,
12✔
577
                                                '{campaignKey}' => $campaign['key'],
12✔
578
                                                '{userId}' => $userId
10✔
579
                                            ],
2✔
580
                                            self::CLASSNAME
10✔
581
                                        );
2✔
582
                                        $result[$campaign['key']] = null;
12✔
583
                                        continue;
22✔
584
                                    }
585
                                } else {
2✔
586
                                    /*
587
                                here mca == -1 so there could only be 2 scenarios,
588
                                1. If revenueProp is defined then eventProperties should have revenueProp key
589
                                2. if revenueProp is not defined then it's a metric of type - Number of times an event has been triggered.
590
                                */
591
                                    if ($doesRevenuePropExist) {
6✔
592
                                        // Error should be logged if eventProperties is not Defined ` OR ` eventProperties does not have revenueProp key
593
                                        if (!isset($eventProperties) || !array_key_exists($goal['revenueProp'], $eventProperties)) {
×
594
                                            LoggerService::log(
×
595
                                                Logger::ERROR,
×
596
                                                'TRACK_API_REVENUE_NOT_PASSED_FOR_REVENUE_GOAL',
×
597
                                                [
598
                                                    '{goalIdentifier}' => $goalIdentifier,
×
599
                                                    '{campaignKey}' => $campaign['key'],
×
600
                                                    '{userId}' => $userId
601
                                                ],
602
                                                self::CLASSNAME
603
                                            );
604
                                            $result[$campaign['key']] = null;
×
605
                                            continue;
15✔
606
                                        }
607
                                    }
608
                                }
609
                            } else {
3✔
610
                                $revProp = $goal['revenueProp'];
×
611
                                $eventProperties[$revProp] = $revenueValue;
15✔
612
                            }
613
                        } elseif (is_null($revenueValue)) {
15✔
614
                            LoggerService::log(
6✔
615
                                Logger::ERROR,
6✔
616
                                'TRACK_API_REVENUE_NOT_PASSED_FOR_REVENUE_GOAL',
6✔
617
                                [
618
                                    '{goalIdentifier}' => $goalIdentifier,
6✔
619
                                    '{campaignKey}' => $campaign['key'],
6✔
620
                                    '{userId}' => $userId
5✔
621
                                ],
1✔
622
                                self::CLASSNAME
5✔
623
                            );
1✔
624
                            $result[$campaign['key']] = null;
6✔
625
                            continue;
6✔
626
                         }
627
                    }
5✔
628

629
                    if (isset($goalIdentifier)) {
84✔
630
                        if (isset($bucketInfo['goalIdentifier'])) {
84✔
631
                            $identifiers = explode("_vwo_", $bucketInfo['goalIdentifier']);
6✔
632
                        } else {
1✔
633
                            $bucketInfo['goalIdentifier'] = '';
78✔
634
                            $identifiers = [];
78✔
635
                        }
636

637

638
                        if (!in_array($goalIdentifier, $identifiers)) {
84✔
639
                            $bucketInfo['goalIdentifier'] .=  "_vwo_$goalIdentifier";
78✔
640
                            if (!empty($this->_userStorageObj)) {
78✔
641
                                $this->variationDecider->userStorageSet($this->_userStorageObj, $userId, $campaign['key'], $bucketInfo, $bucketInfo['goalIdentifier']);
67✔
642
                            }
2✔
643
                        } elseif ($mca != -1) {
19✔
644
                            LoggerService::log(
6✔
645
                                Logger::INFO,
6✔
646
                                'CAMPAIGN_GOAL_ALREADY_TRACKED',
6✔
647
                                [
648
                                    '{goalIdentifier}' => $goalIdentifier,
6✔
649
                                    '{campaignKey}' => $campaign['key'],
6✔
650
                                    '{userId}' => $userId
5✔
651
                                ],
1✔
652
                                self::CLASSNAME
5✔
653
                            );
1✔
654
                            $result[$campaign['key']] = false;
6✔
655
                            continue;
6✔
656
                        }
657
                    }
13✔
658

659
                    if ($this->isEventArchEnabled()) {
78✔
660
                        if ($goal['type'] == "REVENUE_TRACKING" && isset($goal['revenueProp']) && !in_array($goal['revenueProp'], $revenueProps)) {
18✔
661
                            $revenueProps[] = $goal['revenueProp'];
12✔
662
                        }
2✔
663
                        $metricMap[$campaign['id']] = $goal["id"];
18✔
664
                    } else {
3✔
665
                        if (count($campaigns) == 1) {
60✔
666
                            $parameters = ImpressionBuilder::getConversionQueryParams(
42✔
667
                                $this->settings['accountId'],
42✔
668
                                $campaign,
28✔
669
                                $userId,
28✔
670
                                $bucketInfo['id'],
42✔
671
                                $goal,
28✔
672
                                $revenueValue,
28✔
673
                                $this->getSDKKey()
42✔
674
                            );
7✔
675
                            LoggerService::log(
42✔
676
                                Logger::DEBUG,
42✔
677
                                'IMPRESSION_FOR_TRACK_GOAL',
42✔
678
                                ['{properties}' => $this->getAllowedToLogImpressionParams($parameters)],
42✔
679
                                self::CLASSNAME
35✔
680
                            );
7✔
681
                            $resp = $this->eventDispatcher->sendAsyncRequest(CommonUtil::getUrl(Urls::TRACK_GOAL_ENDPOINT), 'GET', $parameters);
42✔
682
                            if ($resp) {
42✔
683
                                LoggerService::log(
12✔
684
                                    Logger::INFO,
12✔
685
                                    'IMPRESSION_SUCCESS',
12✔
686
                                    [
687
                                        '{endPoint}' => Urls::TRACK_GOAL_ENDPOINT,
12✔
688
                                        '{mainKeys}' => json_encode(["campaignId" => $campaign['id'], "variationId" => $bucketInfo['id'], "goalId" => $goal['id']]),
12✔
689
                                        '{accountId}' => $this->settings['accountId']
12✔
690
                                    ],
2✔
691
                                    self::CLASSNAME
35✔
692
                                );
2✔
693
                            }
2✔
694
                        } else {
7✔
695
                            $batchEventData["ev"][] = ImpressionBuilder::getTrackBatchEventData($this->settings['accountId'], $userId, $campaign['id'], $bucketInfo['id'], $goal, $revenueValue);
18✔
696
                        }
697
                    }
698

699
                    if ($this->isDevelopmentMode) {
78✔
700
                        $result[$campaign['key']] = true;
66✔
701
                        continue;
66✔
702
                    }
703

704
                    $result[$campaign['key']] = true;
12✔
705
                } else {
2✔
706
                    LoggerService::log(
×
707
                        Logger::ERROR,
×
708
                        'TRACK_API_GOAL_NOT_FOUND',
×
709
                        ['{campaignKey}' => $campaign['key'], '{userId}' => $userId, "{goalIdentifier}" => $goalIdentifier],
×
710
                        self::CLASSNAME
711
                    );
712

713
                    $result[$campaign['key']] = null;
10✔
714
                }
715
            } catch (Exception $e) {
8✔
716
                LoggerService::log(Logger::ERROR, $e->getMessage(), [], self::CLASSNAME);
10✔
717
            }
718
        }
22✔
719

720
        if ($this->isEventArchEnabled()) {
132✔
721
            $parameters = ImpressionBuilder::getEventsBaseProperties($this->settings['accountId'], $this->getSDKKey(), $goalIdentifier);
30✔
722
            $payload = ImpressionBuilder::getTrackGoalPayloadData(
30✔
723
                $this->settings,
30✔
724
                $userId,
20✔
725
                $goalIdentifier,
20✔
726
                $metricMap,
20✔
727
                $eventProperties
15✔
728
            );
5✔
729

730
            $eventArchResponse = $this->eventDispatcher->sendEventRequest($parameters, $payload);
30✔
731
            if ($eventArchResponse) {
30✔
732
                LoggerService::log(
24✔
733
                    Logger::INFO,
24✔
734
                    'IMPRESSION_SUCCESS_FOR_EVENT_ARCH',
24✔
735
                    [
736
                        '{accountId}' => $parameters["a"],
24✔
737
                        '{event}' => 'visitor property:' . json_encode($payload["d"]["visitor"]["props"]),
24✔
738
                        '{endPoint}' => CommonUtil::getEventsUrl()
24✔
739
                    ],
4✔
740
                    self::CLASSNAME
25✔
741
                );
4✔
742
            }
4✔
743
        } elseif (count($batchEventData)) {
107✔
744
            $parameters = ImpressionBuilder::getBatchEventQueryParams($this->settings['accountId'], $this->getSDKKey(), $this->usageStats->getUsageStats());
18✔
745
            LoggerService::log(
18✔
746
                Logger::DEBUG,
18✔
747
                'IMPRESSION_FOR_TRACK_GOAL',
18✔
748
                ['{properties}' => json_encode($batchEventData)],
18✔
749
                self::CLASSNAME
15✔
750
            );
3✔
751
            $batchEventsResponse = $this->eventDispatcher->sendBatchEventRequest($this->getSDKKey(), $parameters, $batchEventData);
18✔
752
        }
3✔
753

754
        if (count($result) == 0 || (count($batchEventData) && !$batchEventsResponse)) {
132✔
755
            return null;
6✔
756
        }
757
        if (is_string($campaignKey)) {
126✔
758
            return $result[$campaignKey];
108✔
759
        }
760
        return $result;
18✔
761
    }
762

763
    /**
764
     * to send variation name along with api hit to send add visitor hit
765
     *
766
     * @param  string $campaignKey
767
     * @param  string $userId
768
     * @param  array  $options
769
     * @return string|null
770
     */
771
    public function activate($campaignKey, $userId, $options = [])
772
    {
773
        self::$apiName = 'activate';
162✔
774
        LoggerService::setApiName(self::$apiName);
162✔
775

776
        if ($this->isOptedOut()) {
162✔
777
            return false;
12✔
778
        }
779

780
        return $this->getVariation($campaignKey, $userId, $options, 1, self::$apiName);
150✔
781
    }
782

783
    /**
784
     * fetch the variation name
785
     *
786
     * @param  $campaignKey
787
     * @param  $userId
788
     * @param  array  $options
789
     * @param  int    $trackVisitor
790
     * @param  string $apiName
791
     * @return null|string
792
     */
793
    private function getVariation($campaignKey, $userId, $options, $trackVisitor, $apiName)
794
    {
795
        if (empty($userId) || !is_string($campaignKey)) {
180✔
796
            LoggerService::log(Logger::ERROR, 'API_BAD_PARAMETERS', ['{api}' => self::$apiName], self::CLASSNAME);
×
797
            return null;
×
798
        }
799
        $bucketInfo = null;
180✔
800
        try {
801
            $campaign = ValidationsUtil::getCampaignFromCampaignKey($campaignKey, $this->settings, $apiName);
180✔
802
            if ($campaign !== null) {
180✔
803
                if (($campaign['type'] == CampaignTypes::FEATURE_ROLLOUT) || ($campaign['type'] == CampaignTypes::FEATURE_TEST && $trackVisitor == 1)) {
174✔
804
                    LoggerService::log(
6✔
805
                        Logger::ERROR,
6✔
806
                        'API_NOT_APPLICABLE',
6✔
807
                        [
808
                            '{api}' => $trackVisitor == 1 ? 'activate' : 'getVariationName',
6✔
809
                            '{userId}' => $userId,
6✔
810
                            '{campaignKey}' => $campaignKey,
6✔
811
                            '{campaignType}' => $campaign['type']
6✔
812
                        ],
1✔
813
                        self::CLASSNAME
5✔
814
                    );
1✔
815
                    return $bucketInfo;
146✔
816
                }
817
            } else {
29✔
818
                return $bucketInfo;
6✔
819
            }
820
            $bucketInfo = $this->variationDecider->fetchVariationData($this->_userStorageObj, $campaign, $userId, $options, $trackVisitor ? 'activate' : 'getVariationName');
174✔
821
            if ($bucketInfo !== null) {
168✔
822
                if ($trackVisitor) {
138✔
823
                    if ($this->isEligibleToSendImpressionToVWO()) {
102✔
824
                        if ($this->isEventArchEnabled()) {
78✔
825
                            $parameters = ImpressionBuilder::getEventsBaseProperties($this->settings['accountId'], $this->getSDKKey(), EventEnum::VWO_VARIATION_SHOWN, $this->usageStats->getUsageStats());
6✔
826
                            $payload = ImpressionBuilder::getTrackUserPayloadData(
6✔
827
                                $this->settings,
6✔
828
                                $userId,
4✔
829
                                EventEnum::VWO_VARIATION_SHOWN,
6✔
830
                                $campaign['id'],
6✔
831
                                $bucketInfo['id']
6✔
832
                            );
1✔
833
                            $this->eventDispatcher->sendEventRequest($parameters, $payload);
6✔
834
                        } else {
1✔
835
                            $parameters = ImpressionBuilder::getVisitorQueryParams(
72✔
836
                                $this->settings['accountId'],
72✔
837
                                $campaign,
48✔
838
                                $userId,
48✔
839
                                $bucketInfo['id'],
72✔
840
                                $this->getSDKKey()
72✔
841
                            );
12✔
842

843
                            $parameters =  array_merge($parameters, $this->usageStats->getUsageStats());
72✔
844
                            $this->eventDispatcher->sendAsyncRequest(CommonUtil::getUrl(Urls::TRACK_USER_ENDPOINT), 'GET', $parameters);
72✔
845
                            LoggerService::log(
72✔
846
                                Logger::DEBUG,
72✔
847
                                'IMPRESSION_FOR_TRACK_USER',
72✔
848
                                ['{properties}' => $this->getAllowedToLogImpressionParams($parameters)],
72✔
849
                                self::CLASSNAME
60✔
850
                            );
12✔
851
                        }
852

853
                        if (!$this->isDevelopmentMode) {
78✔
854
                            if ($this->isEventArchEnabled()) {
6✔
855
                                LoggerService::log(
×
856
                                    Logger::INFO,
×
857
                                    'IMPRESSION_SUCCESS_FOR_EVENT_ARCH',
×
858
                                    [
859
                                        '{accountId}' => $parameters["a"],
×
860
                                        '{event}' => 'visitor property:' . json_encode($payload["d"]["visitor"]["props"]),
×
861
                                        '{endPoint}' => CommonUtil::getEventsUrl()
×
862
                                    ]
863
                                );
864
                            } else {
865
                                LoggerService::log(
6✔
866
                                    Logger::INFO,
6✔
867
                                    'IMPRESSION_SUCCESS',
6✔
868
                                    [
869
                                        '{mainKeys}' => json_encode(["campaignId" => $campaign['id'], "variationId" => $bucketInfo['id']]),
6✔
870
                                        '{endPoint}' => Urls::TRACK_USER_ENDPOINT,
6✔
871
                                        '{accountId}' => $this->settings['accountId']
6✔
872
                                    ],
1✔
873
                                    self::CLASSNAME
65✔
874
                                );
1✔
875
                            }
876
                        }
1✔
877
                    } else {
13✔
878
                        LoggerService::log(
30✔
879
                            Logger::INFO,
30✔
880
                            'CAMPAIGN_USER_ALREADY_TRACKED',
30✔
881
                            ['{userId}' => $userId, '{campaignKey}' => $campaignKey, '{api}' => self::$apiName],
30✔
882
                            self::CLASSNAME
25✔
883
                        );
5✔
884
                    }
885
                }
17✔
886

887
                return $bucketInfo['name'];
163✔
888
            }
889
        } catch (Exception $e) {
21✔
890
            LoggerService::log(Logger::ERROR, $e->getMessage(), [], self::CLASSNAME);
8✔
891
        }
892
        return null;
84✔
893
    }
894

895
    /**
896
     * Gets the variation assigned for the user for the campaign
897
     *
898
     * @param  string $campaignKey
899
     * @param  string $userId
900
     * @param  array  $options
901
     * @return string|null
902
     */
903
    public function getVariationName($campaignKey, $userId, $options = [])
904
    {
905
        self::$apiName = 'getVariationName';
108✔
906
        LoggerService::setApiName(self::$apiName);
108✔
907

908
        if ($this->isOptedOut()) {
108✔
909
            return false;
12✔
910
        }
911
        return $this->getVariation($campaignKey, $userId, $options, 0, self::$apiName);
96✔
912
    }
913

914
    /**
915
     * @param  $tagKey
916
     * @param  $tagValue
917
     * @param  $userId
918
     * @return array
919
     */
920
    public function push($tagKey, $tagValue, $userId = '')
921
    {
922
        self::$apiName = 'push';
30✔
923
        LoggerService::setApiName(self::$apiName);
30✔
924

925
        if ($this->isOptedOut()) {
30✔
926
            return [];
6✔
927
        }
928

929
        $customDimensionMap = [];
24✔
930
        //reshuffling
931
        if (!$userId || is_array($tagKey)) {
24✔
932
            $customDimensionMap = $tagKey;
18✔
933
            $userId = $tagValue;
18✔
934
        } else {
3✔
935
            $customDimensionMap[$tagKey] = $tagValue;
18✔
936
        }
937

938
        try {
939
            list($validParams, $respResult, $customDimensionMap) = ValidationsUtil::pushApiParams($userId, $customDimensionMap);
24✔
940
            if (!$validParams) {
24✔
941
                LoggerService::log(Logger::ERROR, 'API_BAD_PARAMETERS', ['{api}' => self::$apiName], self::CLASSNAME);
12✔
942
                return $respResult;
12✔
943
            }
944

945
            if ($this->isEventArchEnabled()) {
24✔
946
                $parameters = ImpressionBuilder::getEventsBaseProperties($this->settings['accountId'], $this->getSDKKey(), EventEnum::VWO_SYNC_VISITOR_PROP);
6✔
947
                $payload = ImpressionBuilder::getPushPayloadData(
6✔
948
                    $this->settings,
6✔
949
                    $userId,
4✔
950
                    EventEnum::VWO_SYNC_VISITOR_PROP,
6✔
951
                    $customDimensionMap
3✔
952
                );
1✔
953
                $result = $this->eventDispatcher->sendEventRequest($parameters, $payload);
6✔
954
            } else {
1✔
955
                if (count($customDimensionMap) == 1) {
18✔
956
                    foreach ($customDimensionMap as $tagKey => $tagValue) {
12✔
957
                        $parameters = ImpressionBuilder::getPushQueryParams($this->settings['accountId'], $userId, $this->getSDKKey(), $tagKey, $tagValue);
12✔
958
                        LoggerService::log(
12✔
959
                            Logger::DEBUG,
12✔
960
                            'IMPRESSION_FOR_PUSH',
12✔
961
                            ['{properties}' => $this->getAllowedToLogImpressionParams($parameters)],
12✔
962
                            self::CLASSNAME
10✔
963
                        );
2✔
964
                        $result = $this->eventDispatcher->sendAsyncRequest(CommonUtil::getUrl(Urls::PUSH_ENDPOINT), 'GET', $parameters);
12✔
965
                        if ($result) {
6✔
966
                            LoggerService::log(
6✔
967
                                Logger::INFO,
6✔
968
                                'IMPRESSION_SUCCESS',
6✔
969
                                [
970
                                    '{endPoint}' => Urls::PUSH_ENDPOINT,
6✔
971
                                    '{accountId}' => $this->settings['accountId'],
6✔
972
                                    '{mainKeys}' => json_encode(["tags" => $parameters['tags']])
6✔
973
                                ],
1✔
974
                                self::CLASSNAME
5✔
975
                            );
1✔
976
                        }
1✔
977
                    }
1✔
978
                } else {
1✔
979
                    $postData = ImpressionBuilder::getPushBatchEventData($this->settings['accountId'], $userId, $customDimensionMap);
6✔
980
                    LoggerService::log(
6✔
981
                        Logger::DEBUG,
6✔
982
                        'IMPRESSION_FOR_PUSH',
6✔
983
                        ['{properties}' => json_encode($postData)],
6✔
984
                        self::CLASSNAME
5✔
985
                    );
1✔
986
                    $parameters = ImpressionBuilder::getBatchEventQueryParams($this->settings['accountId'], $this->getSDKKey(), $this->usageStats->getUsageStats());
6✔
987
                    $result = $this->eventDispatcher->sendBatchEventRequest($this->getSDKKey(), $parameters, $postData);
6✔
988
                }
989
            }
990

991
            if ($this->isDevelopmentMode) {
18✔
992
                return $this->preparePushResponse($customDimensionMap, true, $respResult);
12✔
993
            } elseif ($result) {
12✔
994
                return $this->preparePushResponse($customDimensionMap, $result, $respResult);
12✔
995
            }
996
        } catch (Exception $e) {
6✔
997
            LoggerService::log(Logger::ERROR, $e->getMessage(), [], self::CLASSNAME);
6✔
998
        }
999

1000
        return [];
6✔
1001
    }
1002

1003
    /**
1004
     * @param array $customDimensionMap
1005
     * @param bool  $result
1006
     * @param array $respResult
1007
     * @return array
1008
     */
1009
    private function preparePushResponse($customDimensionMap, $result, $respResult)
1010
    {
1011
        foreach ($customDimensionMap as $tagKey => $tagValue) {
18✔
1012
            $respResult[$tagKey] = $result;
18✔
1013
        }
3✔
1014
        return $respResult;
18✔
1015
    }
1016

1017
    public function getSDKKey()
1018
    {
1019
        $sdkKey = '';
222✔
1020
        if (isset($this->settings["sdkKey"])) {
222✔
1021
            $sdkKey = $this->settings["sdkKey"];
174✔
1022
        }
29✔
1023
        return $sdkKey;
222✔
1024
    }
1025

1026
    private function isEligibleToSendImpressionToVWO()
1027
    {
1028
        return (empty($this->_userStorageObj) ||
156✔
1029
            !$this->variationDecider->hasStoredVariation
135✔
1030
        );
26✔
1031
    }
1032

1033
    private function getGoalTypeToTrack($options)
1034
    {
1035
        $goalTypeToTrack = null;
144✔
1036
        if (!isset($options['goalTypeToTrack'])) {
144✔
1037
            if ($this->goalTypeToTrack) {
138✔
1038
                $goalTypeToTrack = $this->goalTypeToTrack;
138✔
1039
            } else {
23✔
1040
                $goalTypeToTrack = self::GOAL_TYPES['ALL'];
115✔
1041
            }
1042
        } elseif (array_key_exists($options['goalTypeToTrack'], self::GOAL_TYPES)) {
34✔
1043
            $goalTypeToTrack = $options['goalTypeToTrack'];
6✔
1044
        } else {
1✔
1045
            LoggerService::log(
6✔
1046
                Logger::ERROR,
6✔
1047
                'CONFIG_PARAMETER_INVALID',
6✔
1048
                ['{parameter}' => 'goalTypeToTrack', '{api}' => self::$apiName, '{type}' => 'strings(REVENUE, CUSTOM, ALL)'],
6✔
1049
                self::CLASSNAME
5✔
1050
            );
1✔
1051
        }
1052
        return $goalTypeToTrack;
144✔
1053
    }
1054

1055
    private function getAllowedToLogImpressionParams($parameters)
1056
    {
1057
        unset($parameters['env']);
150✔
1058
        return json_encode($parameters);
150✔
1059
    }
1060

1061
    /**
1062
     * Manually opting out of VWO SDK, No tracking will happen
1063
     *
1064
     * @return bool
1065
     */
1066
    public function setOptOut()
1067
    {
1068
        self::$apiName = 'optOut';
18✔
1069
        LoggerService::setApiName(self::$apiName);
18✔
1070

1071
        LoggerService::log(
18✔
1072
            Logger::INFO,
18✔
1073
            'OPT_OUT_API_CALLED',
18✔
1074
            [],
18✔
1075
            self::CLASSNAME
15✔
1076
        );
3✔
1077

1078
        $this->isOptedOut = true;
18✔
1079
        $this->settings = null;
18✔
1080
        $this->_userStorageObj = null;
18✔
1081
        $this->eventDispatcher = null;
18✔
1082
        $this->variationDecider = null;
18✔
1083
        return $this->isOptedOut;
18✔
1084
    }
1085

1086
    /**
1087
     * Check if VWO SDK is manually opted out
1088
     *
1089
     * @return bool
1090
     */
1091
    private function isOptedOut()
1092
    {
1093
        if ($this->isOptedOut) {
366✔
1094
            LoggerService::log(
12✔
1095
                Logger::INFO,
12✔
1096
                'API_NOT_ENABLED',
12✔
1097
                ['{api}' => self::$apiName],
12✔
1098
                self::CLASSNAME
10✔
1099
            );
2✔
1100
        }
2✔
1101
        return $this->isOptedOut;
366✔
1102
    }
1103

1104
    private function isEventArchEnabled()
1105
    {
1106
        return isset($this->settings['isEventArchEnabled']) && $this->settings['isEventArchEnabled'];
258✔
1107
    }
1108
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc