Analytics

The React Native OpenWeb SDK provides analytics tracking capabilities through the OpenWeb.manager.analytics API, enabling developers to monitor user interactions and integrate with business intelligence systems.

The analytics API consists of two key components:

  • Custom BI Data: A customizable property for adding your own metadata to analytics events
    get customBIData(): Record<string, string>
    set customBIData(value: Record<string, string>)
  • Event Handlers: Callback registration for receiving analytics events
    onAnalyticsEvent(handler: OWAnalyticsHandler): () => void

Event Handlers

Register a handler to receive analytics events:

const unsubscribe = OpenWeb.manager.analytics.onAnalyticsEvent((data) => {
  console.log('Analytics event:', data);
  // Send to your analytics platform
});

// Cleanup when no longer needed
unsubscribe();

Custom Data in Analytics Events

The customData field in OWAnalyticsEventData contains your custom business intelligence data that was set via OpenWeb.manager.analytics.customBIData. This allows you to attach application-specific metadata to every analytics event. It's automatically included with every analytics event, allowing you to enrich your analytics with contextual information about the user, session, or application state.

get customBIData(): Record<string, string>
set customBIData(value: Record<string, string>) 
// Set custom business intelligence data
OpenWeb.manager.analytics.customBIData = {
  userId: '12345',
  userTier: 'premium',
  sessionId: 'abc-def-ghi',
  appVersion: '2.1.0'
};

// Custom data is automatically included in all analytics events
OpenWeb.manager.analytics.onAnalyticsEvent((data) => {
  console.log('Event:', data.eventName);
  console.log('Custom Data:', data.customData);
});

Type Definition

OWAnalyticsEventData

interface OWAnalyticsEventData {
  event: OWAnalyticsEvent;           // The specific event with its data
  postId: string;                    // Unique article identifier
  customData?: Record<string, any>;  // Your custom BI data
}

OWAnalyticsEvent

Event TypeAdditional Data
FullConversationLoadedNone
FullConversationLoadedNone
FullConversationViewedNone
PreConversationViewedNone
CommentViewedcommentId?: string
CommentShareClickedcommentId?: string
CommentReadMoreClickedcommentId?: string
CommentRankUpButtonClickedcommentId?: string
CommentRankDownButtonClickedcommentId?: string
CommentRankUpUndoButtonClicked**commentId?: string
CommentRankDownUndoButtonClickedcommentId?: string
CommentMenuClickedcommentId?: string
CommentMenuClosedcommentId?: string
CommentMenuReportClickedcommentId?: string
CommentMenuDeleteClickedcommentId?: string
CommentMenuConfirmDeleteClickedcommentId?: string
CommentMenuEditClickedcommentId?: string
CommentMenuMuteClickedcommentId?: string
PostCommentClickedNone
PostReplyClickedreplyToCommentId?: string
ReplyClickedreplyToCommentId?: string
EditCommentClickedcommentId?: string
EditCommentClickedNone
CommentCreationClosePageNone
CommentCreationClosePageNone
CommentCreationContinueWritingNone
CameraIconClickedOpenNone
CameraIconClickedTakePhotoNone
CameraIconClickedChooseFromGalleryNone
CameraIconClickedChooseFromGalleryNone
SortByClickedcurrentSort?: OWSortOption
SortByClosedcurrentSort?: OWSortOption
SortByChangedpreviousSort?: OWSortOption
selectedSort?: OWSortOption
LoadMoreCommentspaginationOffset?: number
LoadMoreRepliesClickedcommentId?: string
HideMoreRepliesClickedcommentId?: string
HideMoreRepliesClickedNone
UserProfileClickedNone
MyProfileClickedsource?: OWAvatarSource
SignUpToPostClickedNone
LoginPromptClickedNone
CommunityGuidelinesLinkClickedNone

OWSortOption

Defines the sorting order for comments in a conversation.

export const OWSortOptionType = {
  Best: 'BEST',
  Newest: 'NEWEST',
  Oldest: 'OLDEST',
} as const;

export type OWSortOption =
  | { type: typeof OWSortOptionType.Best }
  | { type: typeof OWSortOptionType.Newest }
  | { type: typeof OWSortOptionType.Oldest };

OWAvatarSource

Identifies where a user avatar was clicked from within the app.

export const OWAvatarSource = {
  Comment: 'comment',
  CommentCreation: 'commentCreation',
  CommentCTA: 'commentCTA',
  Notifications: 'notifications',
} as const;

export type OWAvatarSource =
  | { type: typeof OWAvatarSource.Comment }
  | { type: typeof OWAvatarSource.CommentCreation }
  | { type: typeof OWAvatarSource.CommentCTA }
  | { type: typeof OWAvatarSource.Notifications };