The OWAnalytics protocol in the OpenWeb iOS SDK allows you to track analytics events and set custom business intelligence data.



public protocol OWAnalytics {
    var customBIData: OWCustomBIData { get set }
    func addBICallback(_ callback: @escaping OWBIAnalyticEventCallback)
}

With a callback, you can handle specific analytics events, allowing you to integrate with your BI or analytics systems.


var manager: OWManagerProtocol = OpenWeb.manager

// Analytics

var analytics: OWAnalytics = OpenWeb.manager.analytics
// Set custom BI
let data: OWCustomBIData = ...
analytics.customBIData = data

// Set callback for the events
let analyticClosure: OWBIAnalyticEventCallback = { event, additionalInfo, postId in
    switch element {
      case .sortTypeChanged(let type):
        // Send your own BI/analytics here
      case .default:
        break
    }
}
analytics.addBICallback(analyticBIClosure) // Allow multiple callbacks


Enumerations and Structs

OWBIAnalyticEvent

Setting Description
OWBIAnalyticEvent OWBIAnalyticEvent Analytics event

Possible Values:
  • .cameraIconClickedChooseFromGallery
  • .cameraIconClickedClose
  • .cameraIconClickedOpen
  • .cameraIconClickedTakePhoto
  • .commentCreationClosePage
  • .commentCreationContinueWriting
  • .commentCreationLeavePage
  • .commentMenuClicked(commentId: String)
  • .commentMenuClosed(commentId: String)
  • .commentMenuConfirmDeleteClicked(commentId: String)
  • .commentMenuDeleteClicked(commentId: String)
  • .commentMenuEditClicked(commentId: String)
  • .commentMenuMuteClicked(commentId: String)
  • .commentMenuReportClicked(commentId: String)
  • .commentRankDownButtonClicked(commentId: String)
  • .commentRankDownUndoButtonClicked(commentId: String)
  • .commentRankUpButtonClicked(commentId: String)
  • .commentRankUpUndoButtonClicked(commentId: String)
  • .commentReadMoreClicked(commentId: String)
  • .commentShareClicked(commentId: String)
  • .commentViewed(commentId: String)
  • .createCommentCTAClicked
  • .editCommentClicked(commentId: String)
  • .fullConversationLoaded
  • .fullConversationViewed
  • .hideMoreRepliesClicked(commentId: String)
  • .loadMoreRepliesClicked(commentId: String)
  • .loginPromptClicked
  • .myProfileClicked(source: String)
  • .postCommentClicked
  • .postReplyClicked(replyToCommentId: String)
  • .preConversationLoaded
  • .preConversationViewed
  • .replyClicked(replyToCommentId: String)
  • .showMoreComments
  • .signUpToPostClicked
  • .sortByChanged(previousSort: OWSortOption, selectedSort: OWSortOption)
  • .sortByClicked(currentSort: OWSortOption)
  • .sortByClosed(currentSort: OWSortOption)
  • .userProfileClicked

OWBIAnalyticEventCallback

public typealias OWBIAnalyticEventCallback = (
  event: OWBIAnalyticEvent, 
  additionalInfo: OWBIAnalyticAdditionalInfo, 
  postId: String
) -> Void
Argument Description
additionalInformation OWBIAnalyticAdditionalInfo Custom data defined by the publisher in customBIData
event OWBIAnalyticEvent Subset of a triggered event

See: OWBIAnalyticEvent
postId string Unique article identifier that is specific to the article page

The ideal postId has the following characteristics:
  • Aligns with the URL slug (an-article-title) or article ID (14325)
  • Is less than 50 characters, ideally 15 characters
  • Uses a combination of letters, number, dashes (-), or hyphens (_)
  • Except for the regex [^\w\s\-\:\.\$\~], does not include special characters

OWCustomBIData

Custom data defined by the publisher

typealias OWCustomBIData = [String: Codable]