1 |
efrain |
1 |
/*
|
|
|
2 |
* Copyright 2019 Google
|
|
|
3 |
*
|
|
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
5 |
* you may not use this file except in compliance with the License.
|
|
|
6 |
* You may obtain a copy of the License at
|
|
|
7 |
*
|
|
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
9 |
*
|
|
|
10 |
* Unless required by applicable law or agreed to in writing, software
|
|
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
13 |
* See the License for the specific language governing permissions and
|
|
|
14 |
* limitations under the License.
|
|
|
15 |
*/
|
|
|
16 |
|
|
|
17 |
#import "FirebaseRemoteConfig/Sources/RCNPersonalization.h"
|
|
|
18 |
|
|
|
19 |
#import "FirebaseRemoteConfig/Sources/RCNConfigConstants.h"
|
|
|
20 |
#import "FirebaseRemoteConfig/Sources/RCNConfigValue_Internal.h"
|
|
|
21 |
|
|
|
22 |
@implementation RCNPersonalization
|
|
|
23 |
|
|
|
24 |
- (instancetype)initWithAnalytics:(id<FIRAnalyticsInterop> _Nullable)analytics {
|
|
|
25 |
self = [super init];
|
|
|
26 |
if (self) {
|
|
|
27 |
self->_analytics = analytics;
|
|
|
28 |
self->_loggedChoiceIds = [[NSMutableDictionary alloc] init];
|
|
|
29 |
}
|
|
|
30 |
return self;
|
|
|
31 |
}
|
|
|
32 |
|
|
|
33 |
- (void)logArmActive:(NSString *)rcParameter config:(NSDictionary *)config {
|
|
|
34 |
NSDictionary *ids = config[RCNFetchResponseKeyPersonalizationMetadata];
|
|
|
35 |
NSDictionary<NSString *, FIRRemoteConfigValue *> *values = config[RCNFetchResponseKeyEntries];
|
|
|
36 |
if (ids.count < 1 || values.count < 1 || !values[rcParameter]) {
|
|
|
37 |
return;
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
NSDictionary *metadata = ids[rcParameter];
|
|
|
41 |
if (!metadata) {
|
|
|
42 |
return;
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
NSString *choiceId = metadata[kChoiceId];
|
|
|
46 |
if (choiceId == nil) {
|
|
|
47 |
return;
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
// Listeners like logArmActive() are dispatched to a serial queue, so loggedChoiceIds should
|
|
|
51 |
// contain any previously logged RC parameter / choice ID pairs.
|
|
|
52 |
if (self->_loggedChoiceIds[rcParameter] == choiceId) {
|
|
|
53 |
return;
|
|
|
54 |
}
|
|
|
55 |
self->_loggedChoiceIds[rcParameter] = choiceId;
|
|
|
56 |
|
|
|
57 |
[self->_analytics logEventWithOrigin:kAnalyticsOriginPersonalization
|
|
|
58 |
name:kExternalEvent
|
|
|
59 |
parameters:@{
|
|
|
60 |
kExternalRcParameterParam : rcParameter,
|
|
|
61 |
kExternalArmValueParam : values[rcParameter].stringValue,
|
|
|
62 |
kExternalPersonalizationIdParam : metadata[kPersonalizationId],
|
|
|
63 |
kExternalArmIndexParam : metadata[kArmIndex],
|
|
|
64 |
kExternalGroupParam : metadata[kGroup]
|
|
|
65 |
}];
|
|
|
66 |
|
|
|
67 |
[self->_analytics logEventWithOrigin:kAnalyticsOriginPersonalization
|
|
|
68 |
name:kInternalEvent
|
|
|
69 |
parameters:@{kInternalChoiceIdParam : choiceId}];
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
@end
|