{"id":32297907,"url":"https://github.com/9oya/analytics_logger_gen","last_synced_at":"2025-10-23T04:50:39.678Z","repository":{"id":137734744,"uuid":"609726222","full_name":"9oya/analytics_logger_gen","owner":"9oya","description":"A code generator that generates analytics events for tools like FirebaseAnalytics. Import events from Google Spreadsheets, remote repositories or local CSV files.","archived":false,"fork":false,"pushed_at":"2024-03-29T06:12:15.000Z","size":240,"stargazers_count":13,"open_issues_count":2,"forks_count":5,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-04-24T08:57:35.370Z","etag":null,"topics":["analytics","appsflyer","build-runner","code-generator","dart","dart-codegen","firebase-analytics","flutter","generator","source-gen"],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/analytics_logger_gen","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/9oya.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-03-05T03:21:36.000Z","updated_at":"2024-02-24T12:36:15.000Z","dependencies_parsed_at":null,"dependency_job_id":"f96c2b00-0760-4975-941e-eb84602d4fb9","html_url":"https://github.com/9oya/analytics_logger_gen","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"purl":"pkg:github/9oya/analytics_logger_gen","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/9oya%2Fanalytics_logger_gen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/9oya%2Fanalytics_logger_gen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/9oya%2Fanalytics_logger_gen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/9oya%2Fanalytics_logger_gen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/9oya","download_url":"https://codeload.github.com/9oya/analytics_logger_gen/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/9oya%2Fanalytics_logger_gen/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280563533,"owners_count":26351731,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-23T02:00:06.710Z","response_time":142,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["analytics","appsflyer","build-runner","code-generator","dart","dart-codegen","firebase-analytics","flutter","generator","source-gen"],"created_at":"2025-10-23T04:50:34.599Z","updated_at":"2025-10-23T04:50:39.666Z","avatar_url":"https://github.com/9oya.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# analytics_logger_gen\n\n[analytics_logger_gen](https://github.com/9oya/analytics_logger_gen) is a code generator that generates analytics events for tools like FirebaseAnalytics. Import events from Google Spreadsheets, remote repositories or local CSV files.\n\n## Running the generator\n```shell\ndart pub run build_runner build\n```\n\u003cdetails\u003e\n\u003csummary\u003eOther useful commands\u003c/summary\u003e\n\n```shell\ndart pub run build_runner build --delete-conflicting-outputs\n# if you want to delete the generated files before building\n\ndart pub run build_runner clean\n# if generated files are not updated after modifying the CSV file\n```\n\u003c/details\u003e\n\n## Calling the generated code\nYou can call the generated code from anywhere in your project with `Future` type methods.\n```dart\nawait EventProvider.setup();\n\nEventProvider.appStarted(title: 'Hello', message: 'world');\n```\n\n## Annotation based code generation\nThe builders generate code when they find members annotated with `@AnalyticsLogger`.\n```dart\nimport 'package:analytics_logger_gen/analytics_logger_gen.dart';\n\n// Building creates the corresponding part 'analytics_logger.g.dart'\npart 'analytics_logger.g.dart';\n\n@AnalyticsLogger(\n    // ex) (from project root)assets/logger_gen_example_sheet.csv\n    localCsvPath: '\u003cPATH-TO-CSV-FILE\u003e',\n    // When you declare the localCsvPath, the remoteCsvUrl is ignored.\n    remoteCsvUrl: '\u003cURL-TO-CSV-FILE\u003e',\n    \n    loggers: \u003cType, String\u003e{\n      // The key of the map is the Type of the class that implements the [EventLogger] interface.\n      //\n      // Matching \u003cCSV-COLUMN-NAME\u003e in @AnalyticsLogger with CSV column determines which analytics tool to call for generated events.\n      FirebaseAnalyticsLogger: '\u003cCSV-COLUMN-NAME\u003e',\n    })\n// The class should be declared private '_' to avoid conflicts with the generated class\n// ignore: unused_element\nclass _EventLoggerContainer {}\n\n// You can declare any number of loggers for third-party analytics tools.\nclass FirebaseAnalyticsLogger extends EventLogger {\n  FirebaseAnalyticsLogger();\n\n  final FirebaseAnalytics _analytics = FirebaseAnalytics.instance;\n\n  @override\n  Future\u003cvoid\u003e setup() async {\n    await Firebase.initializeApp();\n    super.setup();\n  }\n\n  @override\n  Future\u003cvoid\u003e logEvent(String event,\n      {required Map\u003cString, dynamic\u003e attributes}) async {\n    switch (EventType.fromName(event)) {\n      case EventType.setUserId:\n        await _analytics.setUserId(\n            id: attributes.values.first?.value.toString());\n        break;\n      case EventType.setUserInfo:\n        for (final entry in attributes.entries) {\n          await _analytics.setUserProperty(\n            name: entry.key,\n            value: entry.value,\n          );\n        }\n        break;\n      default:\n        await _analytics.logEvent(name: event, parameters: attributes);\n    }\n  }}\n  }\n}\n```\n## Examples\n### Calling the generated code\n```dart\nEventProvider.appStarted();\n\nEventProvider.buttonClicked(abTestCase: 'A');\n\nEventProvider.purchase(productId: 'product-id', price: 100, currency: 'USD', quantity: 1);\n```\n### CSV file\n- The indices of the `event_name` and `arguments` columns cannot be modified; they are fixed at column indices 0 and 1, respectively. (You can change their names, but not their indices.)\n- You can add any number of columns to the right of the `arguments` column.\n- Matching columns in the 'loggers' Map property value of @AnalyticsLogger determine which analytics tool to call for generated events.\n- Use [TRUE]/[1] to enable logger, [FALSE]/[0]/[ ] to disable.\n\n| event_name            | arguments               | isFirebaseEnabled | isAppsFlyerEnabled | isAmplitudeEnabled | isMixpanelEnabled | isSingularEnabled | isDatadogEnabled | description                                  |\n|-----------------------|-------------------------|-------------------|--------------------|---------------------|-------------------|--------------------|------------------|----------------------------------------------|\n| app_started           | title, message          | TRUE              | TRUE               | TRUE                | TRUE              | TRUE               | TRUE             |                                              |\n| home_page_entered     | ab_test_case            | TRUE              | TRUE               | TRUE                | TRUE              |                   | TRUE             |                                              |\n| app_ended             |                         | TRUE              | TRUE               | TRUE                | TRUE              | TRUE               |                  |                                              |\n| button_clicked        | ab_test_case            | TRUE              | TRUE               | TRUE                | TRUE              | TRUE               | TRUE             |                                              |\n| select_contents       | content_type, item_id   | TRUE              |                    |                     |                   |                    |                  |                                              |\n| send_message          | title, message          |                   | TRUE               | TRUE                | TRUE              |                   | TRUE             |                                              |\n| banner_clicked        |                         | TRUE              | TRUE               | TRUE                | TRUE              | TRUE               | TRUE             |                                              |\n| set_user_id           | id                      | TRUE              |                    |                     |                   |                    |                  |                                              |\n| set_user_info         | age, gender             | TRUE              |                    |                     |                   |                    |                  |                                              |\n| purchase              | productId, price, currency, quantity | TRUE              |                    |                     |                   |                    |                  |                                              |\n\n\n[download example csv file](https://raw.githubusercontent.com/9oya/analytics_logger_gen_example_public_docs-/main/logger_gen_example_v3.csv)\n\n### Prerequisites for running the code generation\n#### Local CSV file\n```dart\nimport 'package:analytics_logger_gen/analytics_logger_gen.dart';\n\nimport '../event_logger_impls/event_loggers.dart';\n\npart 'logger_from_local_file.g.dart';\n\n@AnalyticsLogger(\n    localCsvPath: 'assets/logger_gen_example_v3.csv',\n    loggers: {\n      FirebaseAnalyticsLogger: 'isFirebaseEnabled',\n      AppsFlyerLogger: 'isAppsFlyerEnabled',\n      AmplitudeLogger: 'isAmplitudeEnabled',\n      MixpanelLogger: 'isMixpanelEnabled',\n      SingularLogger: 'isSingularEnabled',\n      DatadogDebugLogger: 'isDatadogEnabled',\n    },\n    providerName: 'EventProvider',\n    eventTypeName: 'EventType')\n// ignore: unused_element\nclass _EventLoggerContainer {}\n```\n#### Remote CSV file\n```dart\nimport 'package:analytics_logger_gen/analytics_logger_gen.dart';\n\nimport '../event_logger_impls/event_loggers.dart';\n\npart 'logger_from_google_spread_sheet.g.dart';\n\n@AnalyticsLogger(\n    remoteCsvUrl:\n    'https://docs.google.com/spreadsheets/d/e/2PACX-1vSziB4YXy4C777tDDHlW96iT-640jWsfpc0cJLCc114DWxNusSQs61EkrY5lhLcp0T1Wkj1IJWijQ-j/pub?gid=0\u0026single=true\u0026output=csv',\n    loggers: {\n      FirebaseAnalyticsLogger: 'isFirebaseEnabled',\n      AppsFlyerLogger: 'isAppsFlyerEnabled',\n      AmplitudeLogger: 'isAmplitudeEnabled',\n      MixpanelLogger: 'isMixpanelEnabled',\n      SingularLogger: 'isSingularEnabled',\n      DatadogDebugLogger: 'isDatadogEnabled',\n    },\n    providerName: 'EventProvider',\n    eventTypeName: 'EventType')\n// ignore: unused_element\nclass _EventLoggerContainer {}\n\nclass FirebaseAnalyticsLogger extends EventLogger {\n  FirebaseAnalyticsLogger();\n\n  @override\n  Future\u003cvoid\u003e logEvent(String event,\n      {required Map\u003cString, dynamic\u003e attributes}) async {\n    // Do something with the event and attributes\n  }\n}\n\nclass AppsFlyerLogger extends EventLogger {\n  AppsFlyerLogger();\n\n  @override\n  Future\u003cvoid\u003e logEvent(String event,\n      {required Map\u003cString, dynamic\u003e attributes}) async {\n    // Do something with the event and attributes\n  }\n}\n\nclass AmplitudeLogger extends EventLogger {\n  AmplitudeLogger();\n\n  @override\n  Future\u003cvoid\u003e logEvent(String event,\n      {required Map\u003cString, dynamic\u003e attributes}) {\n    // Do something with the event and attributes\n  }\n}\n\nclass MixpanelLogger extends EventLogger {\n  MixpanelLogger();\n\n  @override\n  Future\u003cvoid\u003e logEvent(String event,\n      {required Map\u003cString, dynamic\u003e attributes}) async {\n    // Do something with the event and attributes\n  }\n}\n\nclass SingularLogger extends EventLogger {\n  SingularLogger();\n\n  @override\n  Future\u003cvoid\u003e logEvent(String event,\n      {required Map\u003cString, dynamic\u003e attributes}) async {\n    // Do something with the event and attributes\n  }\n}\n\nclass DatadogDebugLogger extends EventLogger {\n  DatadogDebugLogger();\n\n  @override\n  Future\u003cvoid\u003e logEvent(String event,\n      {required Map\u003cString, dynamic\u003e attributes}) async {\n    // Do something with the event and attributes\n  }\n}\n\n\n```\n### The generated code\n```dart\n// GENERATED CODE - DO NOT MODIFY BY HAND\n\npart of 'main.dart';\n\n// **************************************************************************\n// AnalyticsLoggerGenerator\n// **************************************************************************\n\nenum EventType {\n  appStarted('app_started', true, true, true, true, true, true),\n  homePageEntered('home_page_entered', true, true, true, true, false, true),\n  appEnded('app_ended', true, true, true, true, true, false),\n  buttonClicked('button_clicked', true, true, true, true, true, true),\n  selectContents('select_contents', true, false, false, false, false, false),\n  sendMessage('send_message', false, true, true, true, false, true),\n  countIncreased('countIncreased', true, true, true, true, true, true),\n  bannerClicked('banner_clicked', true, true, true, true, true, true),\n  setUserId('set_user_id', true, false, false, false, false, false),\n  setUserInfo('set_user_info', true, false, false, false, false, false),\n  purchase('purchase', true, false, false, false, false, false);\n\n  const EventType(\n      this.name,\n      this.isFirebaseEnabled,\n      this.isAppsFlyerEnabled,\n      this.isAmplitudeEnabled,\n      this.isMixpanelEnabled,\n      this.isSingularEnabled,\n      this.isDatadogEnabled);\n  final String name;\n  final bool isFirebaseEnabled;\n  final bool isAppsFlyerEnabled;\n  final bool isAmplitudeEnabled;\n  final bool isMixpanelEnabled;\n  final bool isSingularEnabled;\n  final bool isDatadogEnabled;\n\n  static EventType fromName(String name) {\n    switch (name) {\n      case 'app_started':\n        return EventType.appStarted;\n      case 'home_page_entered':\n        return EventType.homePageEntered;\n      case 'app_ended':\n        return EventType.appEnded;\n      case 'button_clicked':\n        return EventType.buttonClicked;\n      case 'select_contents':\n        return EventType.selectContents;\n      case 'send_message':\n        return EventType.sendMessage;\n      case 'countIncreased':\n        return EventType.countIncreased;\n      case 'banner_clicked':\n        return EventType.bannerClicked;\n      case 'set_user_id':\n        return EventType.setUserId;\n      case 'set_user_info':\n        return EventType.setUserInfo;\n      case 'purchase':\n        return EventType.purchase;\n      default:\n        throw ArgumentError('Invalid name: $name');\n    }\n  }\n}\n\nclass EventProvider {\n  EventProvider._();\n\n  static Future\u003cvoid\u003e appStarted({dynamic title, dynamic message}) async {\n    Map\u003cString, dynamic\u003e attributes = \u003cString, dynamic\u003e{\n      'title': title,\n      'message': message,\n    };\n    await EventLoggerContainer.logEvent(EventType.appStarted, attributes);\n  }\n\n  static Future\u003cvoid\u003e homePageEntered({dynamic abTestCase}) async {\n    Map\u003cString, dynamic\u003e attributes = \u003cString, dynamic\u003e{\n      'abTestCase': abTestCase,\n    };\n    await EventLoggerContainer.logEvent(EventType.homePageEntered, attributes);\n  }\n\n  static Future\u003cvoid\u003e appEnded() async {\n    Map\u003cString, dynamic\u003e attributes = \u003cString, dynamic\u003e{};\n    await EventLoggerContainer.logEvent(EventType.appEnded, attributes);\n  }\n\n  static Future\u003cvoid\u003e buttonClicked({dynamic abTestCase}) async {\n    Map\u003cString, dynamic\u003e attributes = \u003cString, dynamic\u003e{\n      'abTestCase': abTestCase,\n    };\n    await EventLoggerContainer.logEvent(EventType.buttonClicked, attributes);\n  }\n\n  static Future\u003cvoid\u003e selectContents(\n      {dynamic contentType, dynamic itemId}) async {\n    Map\u003cString, dynamic\u003e attributes = \u003cString, dynamic\u003e{\n      'contentType': contentType,\n      'itemId': itemId,\n    };\n    await EventLoggerContainer.logEvent(EventType.selectContents, attributes);\n  }\n\n  static Future\u003cvoid\u003e sendMessage({dynamic title, dynamic message}) async {\n    Map\u003cString, dynamic\u003e attributes = \u003cString, dynamic\u003e{\n      'title': title,\n      'message': message,\n    };\n    await EventLoggerContainer.logEvent(EventType.sendMessage, attributes);\n  }\n\n  static Future\u003cvoid\u003e countIncreased({dynamic count}) async {\n    Map\u003cString, dynamic\u003e attributes = \u003cString, dynamic\u003e{\n      'count': count,\n    };\n    await EventLoggerContainer.logEvent(EventType.countIncreased, attributes);\n  }\n\n  static Future\u003cvoid\u003e bannerClicked() async {\n    Map\u003cString, dynamic\u003e attributes = \u003cString, dynamic\u003e{};\n    await EventLoggerContainer.logEvent(EventType.bannerClicked, attributes);\n  }\n\n  static Future\u003cvoid\u003e setUserId({dynamic id}) async {\n    Map\u003cString, dynamic\u003e attributes = \u003cString, dynamic\u003e{\n      'id': id,\n    };\n    await EventLoggerContainer.logEvent(EventType.setUserId, attributes);\n  }\n\n  static Future\u003cvoid\u003e setUserInfo({dynamic age, dynamic gender}) async {\n    Map\u003cString, dynamic\u003e attributes = \u003cString, dynamic\u003e{\n      'age': age,\n      'gender': gender,\n    };\n    await EventLoggerContainer.logEvent(EventType.setUserInfo, attributes);\n  }\n\n  static Future\u003cvoid\u003e purchase(\n      {dynamic productId,\n        dynamic price,\n        dynamic currency,\n        dynamic quantity}) async {\n    Map\u003cString, dynamic\u003e attributes = \u003cString, dynamic\u003e{\n      'productId': productId,\n      'price': price,\n      'currency': currency,\n      'quantity': quantity,\n    };\n    await EventLoggerContainer.logEvent(EventType.purchase, attributes);\n  }\n}\n\nclass EventLoggerContainer {\n  EventLoggerContainer._();\n  static FirebaseAnalyticsLogger firebaseAnalyticsLogger =\n  FirebaseAnalyticsLogger();\n  static AppsFlyerLogger appsFlyerLogger = AppsFlyerLogger();\n  static AmplitudeLogger amplitudeLogger = AmplitudeLogger();\n  static MixpanelLogger mixpanelLogger = MixpanelLogger();\n  static SingularLogger singularLogger = SingularLogger();\n  static DatadogDebugLogger datadogDebugLogger = DatadogDebugLogger();\n\n  static Future\u003cvoid\u003e setup() async {\n    await firebaseAnalyticsLogger.setup();\n    await appsFlyerLogger.setup();\n    await amplitudeLogger.setup();\n    await mixpanelLogger.setup();\n    await singularLogger.setup();\n    await datadogDebugLogger.setup();\n  }\n\n  static Future\u003cvoid\u003e logEvent(\n      EventType event, Map\u003cString, dynamic\u003e attributes) async {\n    if (event.isFirebaseEnabled) {\n      await firebaseAnalyticsLogger.logEvent(event.name,\n          attributes: attributes);\n    }\n    if (event.isAppsFlyerEnabled) {\n      await appsFlyerLogger.logEvent(event.name, attributes: attributes);\n    }\n    if (event.isAmplitudeEnabled) {\n      await amplitudeLogger.logEvent(event.name, attributes: attributes);\n    }\n    if (event.isMixpanelEnabled) {\n      await mixpanelLogger.logEvent(event.name, attributes: attributes);\n    }\n    if (event.isSingularEnabled) {\n      await singularLogger.logEvent(event.name, attributes: attributes);\n    }\n    if (event.isDatadogEnabled) {\n      await datadogDebugLogger.logEvent(event.name, attributes: attributes);\n    }\n  }\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F9oya%2Fanalytics_logger_gen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F9oya%2Fanalytics_logger_gen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F9oya%2Fanalytics_logger_gen/lists"}