Skip to content

Commit c7614e1

Browse files
Pull request #22: Fix - Track goal missing on Same Event Name
Merge in SST/mobile-testing-ios-sdk from VB-11055 to feature/data360 * commit 'd978a8638b98d3d72880ea54a0bb29af28afb367': Fix - Track goal missing on Same Event Name
2 parents 47c8a22 + d978a86 commit c7614e1

File tree

3 files changed

+53
-41
lines changed

3 files changed

+53
-41
lines changed

VWO/Models/VWOCampaign.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ typedef NS_ENUM(NSInteger, CampaignStatus) {
3636
-(nullable instancetype)setGroups:(NSDictionary *) campaignDict;
3737
- (nullable id)variationForKey:(NSString *)key;
3838
- (nullable id)testKey:(NSString *)testKey;
39-
- (nullable VWOGoal *)goalForIdentifier:(NSString *)identifier;
39+
- (nullable NSMutableArray <VWOGoal *>*)goalForIdentifier:(NSString *)identifier;
4040

4141
@end
4242

VWO/Models/VWOCampaign.m

+4-3
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,15 @@ - (nullable id)variationForKey:(NSString *)key {
120120
return self.variation.changes[key];
121121
}
122122

123-
- (nullable VWOGoal *)goalForIdentifier:(NSString *)identifier {
123+
- (nullable NSMutableArray <VWOGoal *>*)goalForIdentifier:(NSString *)identifier {
124124
NSParameterAssert(identifier);
125+
NSMutableArray <VWOGoal *>*matchedGoalsArray = [NSMutableArray new];
125126
for (VWOGoal *goal in self.goals) {
126127
if ([goal.identifier isEqualToString:identifier]) {
127-
return goal;
128+
[matchedGoalsArray addObject:goal];
128129
}
129130
}
130-
return nil;
131+
return matchedGoalsArray;
131132
}
132133

133134
-(nullable VWOGroup *)groupForMeg{

VWO/VWOController.m

+48-37
Original file line numberDiff line numberDiff line change
@@ -204,51 +204,62 @@ - (void)trackConversion:(NSString *)goalIdentifier withValue:(NSNumber *)value {
204204

205205
//Check if the goal is already marked.
206206
for (VWOCampaign *campaign in _campaignList) {
207-
VWOGoal *matchedGoal = [campaign goalForIdentifier:goalIdentifier];
208-
if (matchedGoal) {
209-
210-
if ([VWOUserDefaults isGoalMarked:matchedGoal inCampaign:campaign]) {
211-
BOOL isEventArchEnabled = [VWOUserDefaults IsEventArchEnabled];
212-
if(!isEventArchEnabled){
213-
VWOLogDebug(@"Goal '%@' already marked and eventArch is not enabled. Will not be marked again", matchedGoal);
214-
return;
215-
}
216-
if([matchedGoal mca] != -1){
217-
//if mca flag != -1, then goal is not triggered multiple times.
218-
VWOLogDebug(@"Goal '%@' already marked. Will not be marked again", matchedGoal);
219-
return;
207+
NSMutableArray <VWOGoal *>*matchedGoals = [campaign goalForIdentifier:goalIdentifier];
208+
if([matchedGoals count] == 0){
209+
continue;
210+
}
211+
212+
for(VWOGoal *matchedGoal in matchedGoals){
213+
if (matchedGoal) {
214+
215+
if ([VWOUserDefaults isGoalMarked:matchedGoal inCampaign:campaign]) {
216+
BOOL isEventArchEnabled = [VWOUserDefaults IsEventArchEnabled];
217+
if(!isEventArchEnabled){
218+
VWOLogDebug(@"Goal '%@' already marked and eventArch is not enabled. Will not be marked again", matchedGoal);
219+
return;
220+
}
221+
if([matchedGoal mca] != -1){
222+
//if mca flag != -1, then goal is not triggered multiple times.
223+
VWOLogDebug(@"Goal '%@' already marked. Will not be marked again", matchedGoal);
224+
return;
225+
}
220226
}
221227
}
222228
}
223229
}
224230

225231
// Mark goal(Goal can be present in multiple campaigns
226232
for (VWOCampaign *campaign in _campaignList) {
227-
VWOGoal *matchedGoal = [campaign goalForIdentifier:goalIdentifier];
228-
if (matchedGoal) {
229-
if ([VWOUserDefaults isTrackingUserForCampaign:campaign]) {
230-
[VWOUserDefaults markGoalConversion:matchedGoal inCampaign:campaign];
231-
232-
NSURL *url = NULL;
233-
if((VWOUserDefaults.IsEventArchEnabled != NULL) &&
234-
([VWOUserDefaults.IsEventArchEnabled isEqualToString:EventArchEnabled])){
235-
//for Event based API calls
236-
url = [_vwoURL forMarkingGoalEventArch:matchedGoal
237-
withValue:value
238-
campaign:campaign
239-
dateTime:NSDate.date];
240-
}else{
241-
//for previous version support
242-
url = [_vwoURL forMarkingGoal:matchedGoal
243-
withValue:value
244-
campaign:campaign
245-
dateTime:NSDate.date];
233+
NSMutableArray <VWOGoal *>*matchedGoals = [campaign goalForIdentifier:goalIdentifier];
234+
if([matchedGoals count] == 0){
235+
continue;
236+
}
237+
for(VWOGoal *matchedGoal in matchedGoals){
238+
if (matchedGoal) {
239+
if ([VWOUserDefaults isTrackingUserForCampaign:campaign]) {
240+
[VWOUserDefaults markGoalConversion:matchedGoal inCampaign:campaign];
241+
242+
NSURL *url = NULL;
243+
if((VWOUserDefaults.IsEventArchEnabled != NULL) &&
244+
([VWOUserDefaults.IsEventArchEnabled isEqualToString:EventArchEnabled])){
245+
//for Event based API calls
246+
url = [_vwoURL forMarkingGoalEventArch:matchedGoal
247+
withValue:value
248+
campaign:campaign
249+
dateTime:NSDate.date];
250+
}else{
251+
//for previous version support
252+
url = [_vwoURL forMarkingGoal:matchedGoal
253+
withValue:value
254+
campaign:campaign
255+
dateTime:NSDate.date];
256+
}
257+
258+
NSString *description = [NSString stringWithFormat:@"Goal %@", matchedGoal];
259+
[pendingURLQueue enqueue:url maxRetry:10 description:description];
260+
} else {
261+
VWOLogWarning(@"Goal %@ not tracked for %@ as user is not tracked", matchedGoal, campaign);
246262
}
247-
248-
NSString *description = [NSString stringWithFormat:@"Goal %@", matchedGoal];
249-
[pendingURLQueue enqueue:url maxRetry:10 description:description];
250-
} else {
251-
VWOLogWarning(@"Goal %@ not tracked for %@ as user is not tracked", matchedGoal, campaign);
252263
}
253264
}
254265
}

0 commit comments

Comments
 (0)