Quick start guides are available in the GitHub repos:
Swift Package Manager guideCocoaPods guideAvoInspector is available through CocoaPods. To install it, simply add the following line to your Podfile:
RubyCopy1pod 'AvoInspector'
The latest version can be found in GitHub releases tab.
SwiftCopy1import AvoInspector
Objective CCopy1#import <AvoInspector/AvoInspector.h>
Obtain the API key in Inspector tab in your Avo.app workspace.
You will need to create an instance of AvoInspector
with the constructor.
SwiftCopy1init(apiKey: String?, env: AvoInspectorEnv)
Objective CCopy1-(instancetype) initWithApiKey: (NSString *) apiKey env: (AvoInspectorEnv) env;
Parameters:
String apiKey
- the API key you get in Inspector tab of your Avo workspaceAvoInspectorEnv env
- current environment: development, staging or production
This is the core of the Avo Inspector SDK.
Call **one of the methods** in this section every time an event is tracked.
SwiftCopy1func trackSchema(fromEvent eventName: String?, eventParams params: [String : Any?]?) -> [String : AvoEventSchemaType]?
Objective CCopy1-(NSDictionary<NSString *, AvoEventSchemaType *> *) trackSchemaFromEvent:(NSString *) eventName eventParams:(NSDictionary<NSString *, id> *) params;
Parameters:
eventName: String
- event name, sometimes referred as event type.eventProperties: NSDictionary<NSString *, id> *
- event properties, which will be converted to event schema on the device and the event schema will be sent to Avo. Resulting keys will be the same and resulting values will be original value's types converted to schema types.Example format:
SwiftCopy12345let eventProperties: [String : Any] = ["userId": 1337,"emailAddress": "jane.doe@avo.app","key": "value"]Objective CCopy12345NSDictionary<NSString *, id> *eventProperties = @{@"userId": @1337,@"emailAddress": @"jane.doe@avo.app",@"key": @"value"};
Return Type:
NSDictionary<NSString *, AvoEventSchemaType *> *
containing event schema, so you can verify that conversion was correct.Example format:
SwiftCopy12345let eventSchema: [String : AvoEventSchemaType] = ["userId": AvoInt(),"emailAddress": AvoString(),"key": AvoString()]Objective CCopy12345NSDictionary<NSString _, AvoEventSchemaType _> \*eventSchema = @{@"userId": [AvoInt new],@"emailAddress": [AvoString new],@"key": [AvoString new]};
SwiftCopy1func trackSchema(eventName: String, eventSchema: NSDictionary<String, AvoEventSchemaType>)
Objective CCopy1-(void) trackSchema:(NSString *) eventName eventSchema:(NSDictionary<NSString *, AvoEventSchemaType *> *) schema;
This method allows you to process the event schema before sending it.
It's handy to extract the schema from your event properties with extractSchema(eventProperties: NSDictionary<String, Any>)
(see below), process it and then provide it to this method.
Parameters:
eventName: String
- event name, sometimes referred as event type.eventSchema: NSDictionary<String *, AvoEventSchemaType *> *
- actual event schema that will be sent to Avo. Keys are event properties names and values are event properties types.Example format:
SwiftCopy12345let eventSchema: [String : AvoEventSchemaType] = ["userId": AvoInt(),"emailAddress": AvoString(),"key": AvoString()]Objective CCopy12345NSDictionary<String _, AvoEventSchemaType _> \*eventSchema = @{@"userId": [AvoInt new],@"emailAddress": [AvoString new],@"key": [AvoString new]};
See this for details about event schema structure and schema types.
SwiftCopy1func extractSchema(eventProperties: NSDictionary<String, Any>) -> NSDictionary<String, AvoEventSchemaType>
Objective CCopy1-(NSDictionary<NSString _, AvoEventSchemaType _> _) extractSchema:(NSDictionary<NSString _, id> \*) eventParams;
This is the method used by trackSchemaFromEvent
internally. It extracts the event schema in form of an NSDictionary
from an event properties NSDictionary.
Parameters:
eventProperties: NSDictionary
- event properties object. Keys are event properties names and values are event properties values.Return Type:
NSDictionary<NSString *, AvoEventSchemaType *> *
containing event schema of the given event properties. Keys are event properties names and values are event properties types. Example format:SwiftCopy123456let eventSchema: [String : AvoEventSchemaType] = ["userId": AvoInt(),"emailAddress": AvoString(),"key": AvoString()]Objective CCopy12345NSDictionary<NSString _, AvoEventSchemaType _> \*eventSchema = @{@"userId": [AvoInt new],@"emailAddress": [AvoString new],@"key": [AvoString new]};
SwiftCopy1func enableLogging(enable: Bool)
Objective CCopy1+(void) enableLogging:(BOOL) enable;
This is a class method.
enableLogging
controls printing of tracked event schemas and other helpful information. Enabled by default in development environments.
Parameters:
enable: Bool
- sets whether Avo Inspector SDK will print logs.
SwiftCopy1func setBatchSize(newBatchSize: Int32)
Objective CCopy1+(void) setBatchSize:(int) newBatchSize;
This is a class method. Enables manual control over events batching. Default batch size in production is 30, i.e. the library attempts to send event schemas to the server when it has 30 or more schemas. In development batching is disabled by default.
Parameters:
newBatchSize: Int32
- sets batch size.
SwiftCopy1func setBatchFlushSeconds(newBatchFlushSeconds: Int32)
Objective CCopy1+(void) setBatchFlushSeconds: (int) newBatchFlushSeconds;
This is a class method. Enables manual control over events batching. Default production batch flush interval is 30 seconds, i.e. the library attempts to send event schemas to the server when 30 or more seconds pass, given there are unsent schemas.
Parameters:
newBatchFlushSeconds: Int32
- sets batch flush time in seconds.
To use the Visual Inspector with Swift Package Manager you need to include it manually from https://github.com/avohq/ios-analytics-debugger-spm
Visual inspector is actually our Mobile Debugger integrated in Avo Inspector SDK.
Visual Inspector is enabled in development and staging environments by default.
SwiftCopy1func show(type: AvoVisualInspectorType)
Objective CCopy1- (void) showVisualInspector: (AvoVisualInspectorType) type;
SwiftCopy1func hideVisualInspector()
Objective CCopy1- (void) hideVisualInspector;
AnalyticsDebugger
SwiftCopy1func getVisualInspector(): AnalyticsDebugger?
Objective CCopy1- (AnalyticsDebugger *) getVisualInspector;
See more about the AnalyticsDebugger in it's GitHub repo.
Here is a code snippet you can use to easily integrate with Segment.
After registering this middleware every events sent to Segment will be automatically analyzed by Avo, i.e. you don't need to call trackSchemaFromEvent
or trackSchema
methods.
SwiftCopy12345678910let config = SEGAnalyticsConfiguration(writeKey: "YOUR_WRITEKEY_HERE")let avoMiddleware = SEGBlockMiddleware { (context, next) inif let trackPayload = context.payload as? SEGTrackPayload {avoInspector.trackSchema(fromEvent: trackPayload.event, eventParams: Dictionary(uniqueKeysWithValues:trackPayload.properties?.map { key, value in (key.description, value) } ?? []))}next(context)}config.middlewares = [ avoMiddleware ]SEGAnalytics.setup(with: config)
Objective CCopy1234567891011SEGAnalyticsConfiguration * config = [SEGAnalyticsConfiguration configurationWithWriteKey: @"YOUR_WRITEKEY_HERE"];SEGBlockMiddleware * avoMiddleware = [[SEGBlockMiddleware alloc] initWithBlock:^(SEGContext * _Nonnull context, SEGMiddlewareNext _Nonnull next) {SEGPayload * payload = [context payload];if ([payload isKindOfClass:[SEGTrackPayload class]]) {SEGTrackPayload * trackPayload = (SEGTrackPayload *) payload;[avoInspector trackSchemaFromEvent:[trackPayload event] eventParams:[trackPayload properties]];}next(context);}];config.middlewares = @[avoMiddleware];[SEGAnalytics setupWithConfiguration:config];
See Segment iOS middleware docs for more information.