Docs
v8
v7
API Docs

Events

The PhotoEditor SDK allows you to register an object that’s notified about events and screen views in real-time. You can then send these events to an analytics service of your choice.

To receive events you need to prepare an object that conforms to the AnalyticsClient protocol and register it with the Analytics service using Analytics.addAnalyticsClient(_:). The corresponding methods of the protocol are called for screen views and events that are defined in the IMGLYAnalyticsScreenViewName and IMGLYAnalyticsEventName constants.

This is a sample implementation for a Google Analytics tracker:

class AnalyticsClient: imglyKit.AnalyticsClient {
  public func logScreenView(_ screenView: IMGLYAnalyticsScreenViewName) {
    func parameters(forScreenName screenName: String) -> [NSObject: AnyObject] {
      return GAIDictionaryBuilder.createScreenView().set(screenName, forKey: kGAIScreenName).build() as [NSObject: AnyObject]
    }

    let tracker = GAI.sharedInstance().defaultTracker

    switch screenView {
    case IMGLYAnalyticsScreenViewName.camera:
      tracker?.send(parameters(forScreenName: "camera"))
    case IMGLYAnalyticsScreenViewName.editor:
      tracker?.send(parameters(forScreenName: "editor"))
    case IMGLYAnalyticsScreenViewName.transform:
      tracker?.send(parameters(forScreenName: "transform"))
    case IMGLYAnalyticsScreenViewName.filter:
      tracker?.send(parameters(forScreenName: "filter"))
    case IMGLYAnalyticsScreenViewName.adjust:
      tracker?.send(parameters(forScreenName: "adjust"))
    case IMGLYAnalyticsScreenViewName.textAdd:
      tracker?.send(parameters(forScreenName: "text add"))
    case IMGLYAnalyticsScreenViewName.text:
      tracker?.send(parameters(forScreenName: "text"))
    case IMGLYAnalyticsScreenViewName.textFont:
      tracker?.send(parameters(forScreenName: "text font"))
    case IMGLYAnalyticsScreenViewName.textFontColor:
      tracker?.send(parameters(forScreenName: "text font color"))
    case IMGLYAnalyticsScreenViewName.textBackgroundColor:
      tracker?.send(parameters(forScreenName: "text background color"))
    case IMGLYAnalyticsScreenViewName.stickerAdd:
      tracker?.send(parameters(forScreenName: "sticker add"))
    case IMGLYAnalyticsScreenViewName.sticker:
      tracker?.send(parameters(forScreenName: "sticker"))
    case IMGLYAnalyticsScreenViewName.stickerColor:
      tracker?.send(parameters(forScreenName: "sticker color"))
    case IMGLYAnalyticsScreenViewName.frame:
      tracker?.send(parameters(forScreenName: "frame"))
    case IMGLYAnalyticsScreenViewName.brush:
      tracker?.send(parameters(forScreenName: "brush"))
    case IMGLYAnalyticsScreenViewName.brushColor:
      tracker?.send(parameters(forScreenName: "brush color"))
    case IMGLYAnalyticsScreenViewName.focus:
      tracker?.send(parameters(forScreenName: "focus"))
    default:
      break
    }
  }

  public func logEvent(_ event: IMGLYAnalyticsEventName, attributes: [IMGLYAnalyticsEventAttributeName : Any]?) {
  }
}

Prior to presenting any PhotoEditor SDK related view controllers, you would then call

PESDK.shared.analytics.isEnabled = true
PESDK.shared.analytics.addAnalyticsClient(AnalyticsClient())

to enable analytics and add your custom tracker to receive events.