Skip to content

Commit

Permalink
fix(Data360Metrics-UserStorage): track multiple trigger goals and goa…
Browse files Browse the repository at this point in the history
…ls with where condition even if present in user storage
  • Loading branch information
rohitesh-wingify committed Oct 17, 2023
1 parent 7b81015 commit 13394ed
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.64.0] - 2023-10-17

### Fixed

- Issue with multiple trigger goals and goals with where condition not getting triggered multiple times if user storage connected

## [1.62.0] - 2023-10-13

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion src/Utils/ImpressionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ImpressionBuilder
/**
* sdk version for api hit
*/
const SDK_VERSION = '1.62.0';
const SDK_VERSION = '1.64.0';
/**
* sdk langauge for api hit
*/
Expand Down
5 changes: 3 additions & 2 deletions src/VWO.php
Original file line number Diff line number Diff line change
Expand Up @@ -654,13 +654,14 @@ public function track($campaignKey = '', $userId = '', $goalIdentifier = '', arr
$identifiers = [];
}



$checkHasProps = isset($goal['hasProps']) ? $goal['hasProps'] : false;
if (!in_array($goalIdentifier, $identifiers)) {
$bucketInfo['goalIdentifier'] .= "_vwo_$goalIdentifier";
if (!empty($this->_userStorageObj)) {
$this->variationDecider->userStorageSet($this->_userStorageObj, $userId, $campaign['key'], $bucketInfo, $bucketInfo['goalIdentifier']);
}
} elseif ($mca != -1) {
} elseif (!($goal['type'] == "REVENUE_TRACKING" && $mca != null && $mca == -1) && !($checkHasProps)) {
LoggerService::log(
Logger::INFO,
'CAMPAIGN_GOAL_ALREADY_TRACKED',
Expand Down
89 changes: 88 additions & 1 deletion tests/VWOTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use vwo\Utils\Common;
use vwo\Utils\DataLocationManager;
use vwo\Utils\SegmentEvaluator;
use vwo\Storage\UserStorageInterface;

/***
* Class VWOTest
Expand Down Expand Up @@ -53,6 +54,7 @@ protected function setUp()
$this->settings9 = Settings9::setup();
$this->settingsFileEventProperties = SettingsFileEventProperties::setup();
$this->MABTrueSettingsFile = MABTrueSettingsFile::setup();
$this->settingsFileHasProps = SettingsFileHasProps::setup();
$segmentEvaluatorJson = new SegmentEvaluatorJson();
$results = new VariationResults();

Expand Down Expand Up @@ -1032,7 +1034,7 @@ public function testIfEventPropertiesIsPassedInsteadOfRevenueValue(){
$options = [
'eventProperties' => $eventProperties
];
$response = $vwoInstance->track($campaignKey,'Abby','Track3',$options);
$response = $vwoInstance->track($campaignKey, 'Abby', 'Track3', $options);
$this->assertEquals(true, $response);
}

Expand Down Expand Up @@ -1063,4 +1065,89 @@ public function testWhenMABTrueWithUserStorageEnabled(){
$variation = $vwoInstance->activate($campaignKey, 'George');
$this->assertEquals($variation, 'Control');
}

public function testTrackGoalHasProps()
{
$userStorageInstance = new UserStorageService();
$campaignInfo = [
"userId" => "Ashley",
"campaignKey" => "Track",
"variationName" => "Variation-1",
"goalIdentifier" => "Track1"
];
$userStorageInstance->set($campaignInfo);
$config = [
'settingsFile' => $this->settingsFileHasProps,
'logging' => new CustomLogger(),
'userStorageService' => $userStorageInstance
];
$sdkInstance = new VWO($config);
$result = $sdkInstance->track("Track", "Ashley", "Track1");
$this->assertEquals($result, true);
}

public function testTrackGoalNoHasProps()
{
$userStorageInstance = new UserStorageservice();
$campaignInfo = [
"userId" => "Ashley",
"campaignKey" => "Track",
"variationName" => "Control",
"goalIdentifier" => "Track2"
];
$userStorageInstance->set($campaignInfo);
$config = [
'settingsFile' => $this->settingsFileHasProps,
'logging' => new CustomLogger(),
'userStorageService' => $userStorageInstance
];
$sdkInstance = new VWO($config);
$result = $sdkInstance->track("Track", "Ashley", "Track2");
$this->assertEquals($result, false);
}
}


class UserStorageService implements UserStorageInterface
{
public $campaignStorageArray = array();
private $goalIdentifier = '';

/**
* @param $userId
* @param $campaignKey
* @return array
*/
public function get($userId, $campaignKey)
{
if (is_array($this->campaignStorageArray)) {
//var_dump($this->campaignStorageArray);
foreach ($this->campaignStorageArray as $savedCampaign) {
if (isset($savedCampaign['userId']) && isset($savedCampaign['campaignKey']) && $savedCampaign['userId'] === $userId && $savedCampaign['campaignKey'] === $campaignKey) {
return $savedCampaign;
}
}
}

return null;
}

/**
* @param $campaignInfo
* @return bool
*/

public function set($campaignUserMapping)
{
if (!in_array($campaignUserMapping, $this->campaignStorageArray, true)) {
$this->campaignStorageArray[] = $campaignUserMapping;
}
}
/**
* @param $goalIdentifier
*/
public function setGoalIdentifier($goalIdentifier)
{
$this->goalIdentifier = $goalIdentifier;
}
}
76 changes: 76 additions & 0 deletions tests/assets/SettingsFileHasProps.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

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

namespace vwo;

class SettingsFileHasProps
{
public static function setup()
{
return [
'sdkKey' => 'abcde',
'campaigns' => [
[
'goals' => [
[
'identifier' => 'Track1',
'id' => 216,
'type' => 'CUSTOM_GOAL',
'hasProps' => true
],
[
'identifier' => 'Track2',
'id' => 217,
'type' => 'CUSTOM_GOAL'
],
[
'identifier' => 'Track3',
'id' => 218,
'type' => 'REVENUE_TRACKING',
'revenueProp' => 'abcd'
]
],
'variations' => [
[
'id' => 1,
'name' => 'Control',
'changes' => [],
'weight' => 10
],
[
'id' => 2,
'name' => 'Variation-1',
'changes' => [],
'weight' => 90
]
],
'id' => 233,
'name' => "Track",
'percentTraffic' => 100,
'key' => 'Track',
'status' => 'RUNNING',
'type' => 'VISUAL_AB',
'isForcedVariationEnabled'=> false
]
],
'accountId' => 123456,
'version' => 1,
'isEventArchEnabled' => true
];
}
}
3 changes: 2 additions & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@
require 'TestUtil.php';
require 'assets/SettingsFileBucketing.php';
require 'assets/SettingsFileEventProperties.php';
require 'assets/MABTrueSettingsFile.php';
require 'assets/MABTrueSettingsFile.php';
require 'assets/SettingsFileHasProps.php';

0 comments on commit 13394ed

Please sign in to comment.