@@ -61,65 +61,52 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
61
61
62
62
let defaultNotificationCenter = NotificationCenter . default
63
63
defaultNotificationCenter. addObserver ( forName: NSNotification . Name ( " OptimizelyExperimentActivated " ) , object: nil , queue: nil ) { ( note) in
64
-
65
64
print ( " Received an activation notification: \n " , note)
66
-
67
- let userInfo : Dictionary < String , AnyObject > ? = note. userInfo as! Dictionary < String , AnyObject > ?
68
- if let experiment = userInfo ? [ " experiment " ] as! OPTLYExperiment ? {
69
- if let variation = userInfo ? [ " variation " ] as! OPTLYVariation ? {
70
-
71
- // ---- Amplitude ----
72
- let propertyKey : String ! = " [Optimizely] " + experiment. experimentKey
73
- let identify : AMPIdentify = AMPIdentify ( )
74
- identify. set ( propertyKey, value: variation. variationKey as NSObject !)
75
-
76
- // Track impression event (optional)
77
- let eventIdentifier : String = " [Optimizely] " + experiment. experimentKey + " - " + variation. variationKey
78
- Amplitude . instance ( ) . logEvent ( eventIdentifier)
79
-
80
- // ---- Google Analytics ----
81
- let tracker : GAITracker ? = GAI . sharedInstance ( ) . defaultTracker
82
-
83
- let action : String = " Experiment - " + experiment. experimentKey
84
- let label : String = " Variation - " + variation. variationKey
85
-
86
- // Build and send a non-interaction Event
87
- let builder = GAIDictionaryBuilder . createEvent ( withCategory: " Optimizely " , action: action, label: label, value: nil ) . build ( )
88
- tracker? . send ( builder as [ NSObject : AnyObject ] !)
89
-
90
- // ---- Mixpanel ----
91
- let mixpanel : MixpanelInstance = Mixpanel . mainInstance ( )
92
- mixpanel. registerSuperProperties ( [ propertyKey: variation. variationKey] )
93
- mixpanel. people. set ( property: propertyKey, to: variation. variationKey)
94
- mixpanel. track ( event: eventIdentifier)
65
+ if let userInfo : Dictionary < String , AnyObject > = note. userInfo as! Dictionary < String , AnyObject > ? {
66
+ if let experiment = userInfo [ " experiment " ] as! OPTLYExperiment ? {
67
+ if let variation = userInfo [ " variation " ] as! OPTLYVariation ? {
68
+ // ---- Amplitude ----
69
+ let propertyKey : String ! = " [Optimizely] " + experiment. experimentKey
70
+ let identify : AMPIdentify = AMPIdentify ( )
71
+ identify. set ( propertyKey, value: variation. variationKey as NSObject !)
72
+ // Track impression event (optional)
73
+ let eventIdentifier : String = " [Optimizely] " + experiment. experimentKey + " - " + variation. variationKey
74
+ Amplitude . instance ( ) . logEvent ( eventIdentifier)
75
+ // ---- Google Analytics ----
76
+ let tracker : GAITracker ? = GAI . sharedInstance ( ) . defaultTracker
77
+ let action : String = " Experiment - " + experiment. experimentKey
78
+ let label : String = " Variation - " + variation. variationKey
79
+ // Build and send a non-interaction Event
80
+ let builder = GAIDictionaryBuilder . createEvent ( withCategory: " Optimizely " , action: action, label: label, value: nil ) . build ( )
81
+ tracker? . send ( builder as [ NSObject : AnyObject ] !)
82
+ // ---- Mixpanel ----
83
+ let mixpanel : MixpanelInstance = Mixpanel . mainInstance ( )
84
+ mixpanel. registerSuperProperties ( [ propertyKey: variation. variationKey] )
85
+ mixpanel. people. set ( property: propertyKey, to: variation. variationKey)
86
+ mixpanel. track ( event: eventIdentifier)
87
+ }
95
88
}
96
89
}
97
90
}
98
-
91
+
99
92
defaultNotificationCenter. addObserver ( forName: NSNotification . Name ( " OptimizelyEventTracked " ) , object: nil , queue: nil ) { ( note) in
100
-
101
93
print ( " Received a tracking notification: \n " , note)
102
-
103
- let userInfo : Dictionary < String , AnyObject > ? = note. userInfo as! Dictionary < String , AnyObject > ?
104
-
105
- // ---- Localytics ----
106
- let attributes : NSMutableDictionary = [ : ]
107
-
108
- if let userAttributes = userInfo ? [ " attributes " ] as! Dictionary < String , AnyObject > ? {
109
- attributes. addEntries ( from: userAttributes)
110
- }
111
-
112
- if let userExperimentVariationMapping = userInfo ? [ " ExperimentVariationMapping " ] as? Dictionary < String , AnyObject > ? {
113
- for (key, value) in userExperimentVariationMapping! {
114
- let variation : OPTLYVariation = value as! OPTLYVariation
115
- attributes. setValue ( key, forKey: variation. variationKey)
94
+ if let userInfo : Dictionary < String , AnyObject > = note. userInfo as! Dictionary < String , AnyObject > ? {
95
+ // ---- Localytics ----
96
+ let attributes : NSMutableDictionary = [ : ]
97
+ if let userAttributes = userInfo [ " attributes " ] as! Dictionary < String , AnyObject > ? {
98
+ attributes. addEntries ( from: userAttributes)
99
+ }
100
+ if let userExperimentVariationMapping = userInfo [ " ExperimentVariationMapping " ] as? Dictionary < String , OPTLYVariation > ? {
101
+ for (key, variation) in userExperimentVariationMapping! {
102
+ attributes. setValue ( key, forKey: variation. variationKey)
103
+ }
116
104
}
105
+ // Tag custom event with attributes
106
+ let event : String = userInfo [ " eventKey " ] as! String
107
+ let localyticsEventIdentifier : String = " [Optimizely] " + event
108
+ Localytics . tagEvent ( localyticsEventIdentifier)
117
109
}
118
-
119
- // Tag custom event with attributes
120
- let event : String = userInfo![ " eventKey " ] as! String
121
- let localyticsEventIdentifier : String = " [Optimizely] " + event
122
- Localytics . tagEvent ( localyticsEventIdentifier)
123
110
}
124
111
#endif
125
112
// **************************************************
0 commit comments