8
8
9
9
@implementation SEGLocalyticsIntegration
10
10
11
- + (BOOL ) validateEmail : (NSString *)candidate {
11
+ + (BOOL )validateEmail : (NSString *)candidate {
12
12
NSString *emailRegex = @" [A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\ .[A-Za-z]{2,4}" ;
13
- NSPredicate *emailTest = [NSPredicate predicateWithFormat: @" SELF MATCHES %@" , emailRegex];
13
+ NSPredicate *emailTest =
14
+ [NSPredicate predicateWithFormat: @" SELF MATCHES %@" , emailRegex];
14
15
15
16
return [emailTest evaluateWithObject: candidate];
16
17
}
@@ -30,33 +31,45 @@ - (id)init {
30
31
return self;
31
32
}
32
33
33
- - (void )start
34
- {
34
+ - (void )start {
35
35
NSString *appKey = [self .settings objectForKey: @" appKey" ];
36
36
37
37
[Localytics integrate: appKey];
38
38
39
- NSNumber *sessionTimeoutInterval = [self .settings objectForKey: @" sessionTimeoutInterval" ];
40
- if (sessionTimeoutInterval != nil && [sessionTimeoutInterval floatValue ] > 0 ) {
39
+ NSNumber *sessionTimeoutInterval =
40
+ [self .settings objectForKey: @" sessionTimeoutInterval" ];
41
+ if (sessionTimeoutInterval != nil &&
42
+ [sessionTimeoutInterval floatValue ] > 0 ) {
41
43
[Localytics setSessionTimeoutInterval: [sessionTimeoutInterval floatValue ]];
42
44
}
43
45
44
46
SEGLog (@" LocalyticsIntegration initialized." );
45
47
}
46
48
49
+ - (void )setCustomDimensions : (NSDictionary *)dictionary {
50
+ NSDictionary *customDimensions = self.settings [@" dimensions" ];
51
+
52
+ for (NSString *key in dictionary) {
53
+ if ([customDimensions objectForKey: key] != nil ) {
54
+ NSString *dimension = [customDimensions objectForKey: key];
55
+ [Localytics setValue: [dictionary objectForKey: key]
56
+ forCustomDimension: [dimension integerValue ]];
57
+ }
58
+ }
59
+ }
47
60
48
61
#pragma mark - Settings
49
62
50
- - (void )validate
51
- {
63
+ - (void )validate {
52
64
BOOL hasAppKey = [self .settings objectForKey: @" appKey" ] != nil ;
53
65
self.valid = hasAppKey;
54
66
}
55
67
56
68
#pragma mark - Analytics API
57
69
58
- - (void )identify : (NSString *)userId traits : (NSDictionary *)traits options : (NSDictionary *)options
59
- {
70
+ - (void )identify : (NSString *)userId
71
+ traits : (NSDictionary *)traits
72
+ options : (NSDictionary *)options {
60
73
if (userId) {
61
74
[Localytics setCustomerId: userId];
62
75
}
@@ -77,44 +90,56 @@ - (void)identify:(NSString *)userId traits:(NSDictionary *)traits options:(NSDic
77
90
[Localytics setValue: name forIdentifier: @" customer_name" ];
78
91
}
79
92
93
+ [self setCustomDimensions: traits];
94
+
80
95
// Other traits. Iterate over all the traits and set them.
81
96
for (NSString *key in traits) {
82
- NSString * traitValue = [NSString stringWithFormat: @" %@ " , [traits objectForKey: key]];
83
- [Localytics setValue: traitValue forIdentifier: key];
97
+ NSString *traitValue =
98
+ [NSString stringWithFormat: @" %@ " , [traits objectForKey: key]];
99
+ [Localytics setValue: traitValue
100
+ forProfileAttribute: key
101
+ withScope: LLProfileScopeApplication];
84
102
}
85
103
}
86
104
87
- - (void )track : (NSString *)event properties : ( NSDictionary *) properties options : ( NSDictionary *) options
88
- {
89
- // TODO add support for dimensions
105
+ - (void )track : (NSString *)event
106
+ properties : ( NSDictionary *) properties
107
+ options : ( NSDictionary *) options {
90
108
// TODO add support for value
91
109
92
110
// Backgrounded? Restart the session to add this event.
93
- BOOL isBackgrounded = [[UIApplication sharedApplication ] applicationState ] != UIApplicationStateActive;
111
+ BOOL isBackgrounded = [[UIApplication sharedApplication ] applicationState ] !=
112
+ UIApplicationStateActive;
94
113
if (isBackgrounded) {
95
114
[Localytics openSession ];
96
115
}
97
116
98
117
NSNumber *revenue = [SEGAnalyticsIntegration extractRevenue: properties];
99
118
if (revenue) {
100
- [Localytics tagEvent: event attributes: properties customerValueIncrease: revenue];
119
+ [Localytics tagEvent: event
120
+ attributes: properties
121
+ customerValueIncrease: revenue];
101
122
} else {
102
123
[Localytics tagEvent: event attributes: properties];
103
124
}
104
125
126
+ [self setCustomDimensions: properties];
127
+
105
128
// Backgrounded? Close the session again after the event.
106
129
if (isBackgrounded) {
107
130
[Localytics closeSession ];
108
131
}
109
132
}
110
133
111
- - (void )screen : (NSString *)screenTitle properties : (NSDictionary *)properties options : (NSDictionary *)options
112
- {
134
+ - (void )screen : (NSString *)screenTitle
135
+ properties : (NSDictionary *)properties
136
+ options : (NSDictionary *)options {
113
137
// For enterprise only...
114
138
[Localytics tagScreen: screenTitle];
115
139
}
116
140
117
- - (void )registerForRemoteNotificationsWithDeviceToken : (NSData *)deviceToken options : (NSDictionary *)options {
141
+ - (void )registerForRemoteNotificationsWithDeviceToken : (NSData *)deviceToken
142
+ options : (NSDictionary *)options {
118
143
[Localytics setPushToken: deviceToken];
119
144
}
120
145
@@ -124,33 +149,29 @@ - (void)flush {
124
149
125
150
#pragma mark - Callbacks for app state changes
126
151
127
- - (void )applicationDidEnterBackground
128
- {
152
+ - (void )applicationDidEnterBackground {
153
+ [Localytics dismissCurrentInAppMessage ];
129
154
[Localytics closeSession ];
130
155
[Localytics upload ];
131
156
}
132
157
133
- - (void )applicationWillEnterForeground
134
- {
158
+ - (void )applicationWillEnterForeground {
135
159
[Localytics openSession ];
136
160
[Localytics upload ];
137
161
}
138
162
139
- - (void )applicationWillTerminate
140
- {
163
+ - (void )applicationWillTerminate {
141
164
[Localytics closeSession ];
142
165
[Localytics upload ];
143
166
}
144
- - (void )applicationWillResignActive
145
- {
167
+ - (void )applicationWillResignActive {
168
+ [Localytics dismissCurrentInAppMessage ];
146
169
[Localytics closeSession ];
147
170
[Localytics upload ];
148
171
}
149
- - (void )applicationDidBecomeActive
150
- {
172
+ - (void )applicationDidBecomeActive {
151
173
[Localytics openSession ];
152
174
[Localytics upload ];
153
175
}
154
176
155
-
156
177
@end
0 commit comments