Configuring Analytics via Amplitude
Step 1: Create new Class
Create a new class "AppAmplitude" and add the following method to it.
#import <SmartechNudges/Hansel-umbrella.h>
+ (void) logEvent: (NSString*) eventName withProperties: (id) properties onInstance: (Amplitude*) amplitude{
//Check if this event is being tracked in any one of the active Hansel Interaction Maps.
//Please pass the string "amp" for vendor if you are using Amplitude to track the event.
NSDictionary* hanselData = [HanselTracker logEvent:eventName andVendor:@"amp" withProperties:properties];
if (![properties isKindOfClass:[NSMutableDictionary class]]){
properties = [properties mutableCopy];
}
[properties addEntriesFromDictionary:hanselData];
[amplitude logEvent:eventName withEventProperties:properties];
}
class func logEvent(_ eventName: String,_ properties: [AnyHashable : Any]?,_ amplitude: Amplitude?){
var properties = properties
//Check if this event is being tracked in any one of the active Hansel Interaction Maps.
//Please pass the string "amp" for vendor if you are using Amplitude to track the event.
//getting the data for all interaction maps on hansel dashboard
let hanselData = HanselTracker.logEvent(eventName, vendor: "amp", withProperties: properties)
for (k, v) in hanselData { properties[k] = v }
amplitude?.logEvent(eventName, withEventProperties: properties)
}
Step 2: Update code
For all those events on which you want to track the impact of Hansel changes, make the updates as suggested in the snippet below:
#import <SmartechNudges/Hansel-umbrella.h>
//Continue setting up Product experience
//If the original code was
[[Amplitude instance] logEvent:eventName withEventProperties:properties];
//it would get updated to
[AppAmplitude logEvent:eventName withEventProperties:properties onInstance:[Amplitude instance]];
//If the original code was
Amplitude.instance()?.logEvent(eventName, withEventProperties: properties)
//it would get updated to
AppAmplitude.logEvent(eventName, properties, Amplitude.instance())
Updated 9 months ago