|
| 1 | +/* |
| 2 | + * Copyright (c) 2026 Ashish Yadav <mailtoashish693@gmail.com> |
| 3 | + * |
| 4 | + * This program is free software; you can redistribute it and/or modify it under |
| 5 | + * the terms of the GNU General Public License as published by the Free Software |
| 6 | + * Foundation; either version 3 of the License, or (at your option) any later |
| 7 | + * version. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, but WITHOUT ANY |
| 10 | + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 11 | + * PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| 12 | + * |
| 13 | + * You should have received a copy of the GNU General Public License along with |
| 14 | + * this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 | + */ |
| 16 | +package com.ichi2.anki.common.analytics |
| 17 | + |
| 18 | +/** |
| 19 | + * Analytics interface for tracking events and screen views. |
| 20 | + * |
| 21 | + * Feature modules should use [AnalyticsProvider] to access the instance. |
| 22 | + */ |
| 23 | +interface Analytics { |
| 24 | + /** |
| 25 | + * Send a detailed arbitrary analytics event, with noun/verb pairs and extra data if needed. |
| 26 | + * |
| 27 | + * @param category the category of event, make your own but use a constant so reporting is good |
| 28 | + * @param action the action the user performed |
| 29 | + * @param value a value for the event |
| 30 | + * @param label a label for the event |
| 31 | + */ |
| 32 | + fun sendAnalyticsEvent( |
| 33 | + category: String, |
| 34 | + action: String, |
| 35 | + value: Int? = null, |
| 36 | + label: String? = null, |
| 37 | + ) |
| 38 | + |
| 39 | + /** |
| 40 | + * Submit a screen for aggregation / analysis. |
| 41 | + * Intended for use to determine if / how features are being used. |
| 42 | + * |
| 43 | + * @param screen the result of [Class.getSimpleName] will be used as the screen tag |
| 44 | + */ |
| 45 | + fun sendAnalyticsScreenView(screen: Any) { |
| 46 | + sendAnalyticsScreenView(screen.javaClass.simpleName) |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * Submit a screen display with a synthetic name for aggregation / analysis. |
| 51 | + * Intended for use if your class handles multiple screens you want to track separately. |
| 52 | + * |
| 53 | + * @param screenName the name to show in analysis reports |
| 54 | + */ |
| 55 | + fun sendAnalyticsScreenView(screenName: String) |
| 56 | +} |
| 57 | + |
| 58 | +/** |
| 59 | + * Provides access to the [Analytics] instance. |
| 60 | + * |
| 61 | + * Must be initialized in `AnkiDroidApp.onCreate()` before any analytics calls. |
| 62 | + */ |
| 63 | +object AnalyticsProvider { |
| 64 | + lateinit var instance: Analytics |
| 65 | +} |
0 commit comments