Cognito KMM Template
  • Welcome
  • Getting Started
    • Quickstart: Getting Started
    • Prerequisites
    • Installation
    • Creating New App
  • Architecture
    • Overview
    • Modules
    • Data Flow
  • Feautures
    • Http Client
    • DataStore
    • Analytics
    • AdMob Integration
    • Crash Reporting
    • Built in Settings Page
  • Handle View States
    • StatelessSurface<T> Composable
    • Handle a screen with 3 states
  • Sequential Content with IndefiniteSurface
  • Handle multiple predefined states
  • Showing Paginated Data
  • Handling list data
Powered by GitBook
On this page
  1. Feautures

Analytics

shared/src/commonMain/kotlin/utils/expected/analytics.kt

Integrating Google Analytics

Prerequisites:

  • A Google Analytics account is required.

  • A KMM project set up.

Android Setup:

  1. Obtain Google Services JSON: Acquire the google-services.json file provided by Google.

  2. Place the File: Place the google-services.json file in the root directory of your Android application module.

KMM Integration:

  1. Dependency: Include the appropriate Google Analytics library in your shared module. The specific library might vary depending on your development environment (e.g., firebase-analytics-ktx for Firebase).

Logging Events:

The provided anal() function serves as a convenient way to log events in your KMM code:

Kotlin

fun anal(data: Data, event: Tag.Event = Tag.Event.Select) = Analytics.log(event, data)

Explanation:

  • This function accepts two arguments:

    • data: An object containing the event-specific data to be logged (e.g., user ID, product details).

    • event: An optional Tag.Event enum value (defaults to Tag.Event.Select) that categorizes the event.

  • It utilizes the Analytics.log function (implementation details depend on the chosen library) to send the event data to Google Analytics.

Additional Notes:

  • Consider creating custom event types in your Tag.Event enum for more specific tracking.

  • The actual implementation of the Analytics object and its log function will depend on the specific Google Analytics library you choose for your KMM project.

  • Refer to the chosen library's documentation for detailed information on available functionalities and configuration options.

Benefits of KMM Integration:

  • Unified Tracking: Track user behavior consistently across Android and potentially other platforms you might target with your KMM application.

  • Simplified Code: The anal() function provides a concise way to log events, reducing boilerplate code.

By integrating Google Analytics with your KMM application, you gain valuable insights into user engagement and app usage, enabling data-driven decisions to improve your app's effectiveness.

PreviousDataStoreNextAdMob Integration

Last updated 8 months ago