•  


GitHub - actions-on-google/appactions-common-biis-kotlin at get-analytics-with-firebase
Skip to content

This sample Android app manages items on to-do lists using Google Assistant implemented via App Actions.

License

Notifications You must be signed in to change notification settings

actions-on-google/appactions-common-biis-kotlin

 
 

Repository files navigation

Get analytics for App Actions using Google Analytics for Firebase

TL;DR

This sample demonstrates instrumenting the To-do list App Actions Android App sample to log events using the Google Analytics for Firebase SDK. You can then use Firebase Console to visualize traffic patterns and obtain insights on app usage and user engagement.

Why Google Analytics for Firebase

Google Analytics for Firebase is a free app measurement solution providing insights on user engagement for websites and Android apps (user actions, system events, errors and more). Google Analytics for Firebase can provide insights into different user behaviors with App Actions, notably, the most popular built-in intents (BIIs) used in your app. Further, Google Analytics for Firebase data can be exported to downstream systems like Big Query for further analysis.

Requirements

Before using the sample, you must add Firebase to your App :

  • Add a Firebase configuration file
  • Enable Firebase products in your root-level build.gradle file
  • Apply the Google Service Gradle plugin
  • Add the Google Analytics for Firebase SDK

Once these steps are completed your app will be registered and ready to use Google Analytics for Firebase.

How to use this sample


NOTE

This sample app has already been set up with Google Analytics for Firebase. To set up analytics for your own app, see the "Add Analytics to your app" section below.


Clone or download this project to your preferred location. Then, import and update it to suit your environment:

  1. Switch to get-analytics-with-firebase branch.

    $ git checkout get-analytics-with-firebase
    
  2. In Android Studio, select “Open an existing Android Studio project” from the initial screen or File > Open .

    Change applicationId in app/build.gradle to the applicationId of a draft or published app in Google Play Console.

    android
     {
    defaultConfig {
        
    //
     This ID uniquely identifies your app on device and in Google Play
    
        applicationId 
    "
    com.example.myapp
    "
    
    }
    
  3. In Android Studio, find the root directory of the sample.

  4. Select the build.gradle file.

  5. Follow the instructions in the IDE.

Next, test the App Actions integration:

  1. Build and run the sample on your physical test device (Run "app").

  2. Open the App Actions test tool Tools > App Actions > App Actions Test Tool .

  3. Define an invocation name for App Actions (like "my test app"). This name is only used for testing so it can be different from what is deployed to production.

  4. Click Create Preview . Once your preview is created, the test tool window will update to reflect BIIs found in the actions.xml file.

    Test tool after preview creation

    After creating a preview you can use voice or written commands directly with Assistant on your test device.

    If you run into any issues, check out the troubleshooting issues in our developer documentation.

  5. To view aggregated statistics about your events, navigate to the Google Analytics for Firebase dashboards under Analytics > Streamview . These dashboards update periodically throughout the day. For immediate testing, use the logcat output as described in the previous section.

    You can access events data from the Events dashboard in the Firebase console. This dashboard shows the event reports that are automatically created for each distinct type of event logged by your app.

    Firebase Streamview showing App Actions traffic
  6. View events in the Android Studio debug log.

    You may enable verbose logging of events by the SDK to verify events are being logged properly. This includes both automatic and manually logged events.

    To enable verbose logging, enter this sequence of adb commands from your terminal:

    $ adb shell setprop log.tag.FA VERBOSE
    $ adb shell setprop log.tag.FA-SVC VERBOSE
    $ adb logcat -v 
    time
     -s FA FA-SVC
    

    You should now be able to view events in the Android Studio logcat and verify events are being sent.


    NOTE

    You can also verify Firebase logs with minimal delay in the debug view report by enabling debug mode .


Add Analytics to your app

This section describes how to enable Google Analytics for Firebase in the context of App Actions. Refer to the Firebase Analytics guide for more information.

  1. Add the dependency for the Google Analytics Android library to your module (app-level) Gradle file (usually app/build.gradle):

    implementation 
    '
    com.google.firebase:firebase-analytics-ktx:17.5.0
    '
    
  2. Declare the com.google.firebase.analytics.FirebaseAnalytics object at the top of TaskActivity.kt activity :

    private
     lateinit var 
    firebaseAnalytics
    : 
    FirebaseAnalytics
    
  3. Initialize FirebaseAnalytics in the onCreate() method:

    //
     Obtain the FirebaseAnalytics instance.
    
    firebaseAnalytics 
    =
     Firebase
    .analytics
    
  4. Log events from TasksActivity class. Refer to event logging events documentation for more information:

    override
     fun
     onCreate
    (
    savedInstanceState
    :
     Bundle
    ?
    ) {
      logEventToFirebase(intent.data);
    }
    
    
    /*
    *
    
    * This method will record the event to Google Analytics for Firebase
    
    */
    
    private
     fun
     logEventToFirebase
    (
    data
    :
     Uri
    ?
    ) {
      
    val
     utmCampaign
    :
     String
     =
     data?.getQueryParameter(
    "
    utm_campaign
    "
    ) 
    ?
    :
     N_A
    
      val
     path
    :
     String
     =
     data?.path 
    ?
    :
     N_A
    
      mFirebaseAnalytics.logEvent(
    FirebaseAnalytics
    .
    Event
    .
    APP_OPEN
    ) {
        param(
    FirebaseAnalytics
    .
    Param
    .
    CAMPAIGN
    , utmCampaign)
        param(
    "
    app_action_path
    "
    , path) 
    //
     logging a custom parameter
    
      }
    }
    

    NOTE

    You may include custom params, for instance app_action_path for logging other types of data.


  5. actions.xml needs additional information to indicate the source of the request. Add a url query parameter with the key: utm_campaign and value: appactions :

    <
    fulfillment
     urlTemplate
    =
    "
    https://todo.androidappactions.com/all-tasks?utm_campaign=appactions
    "
    />
    

Contribution guidelines

If you want to contribute to this project, please review the contribution guidelines .

We use GitHub issues for tracking requests and bugs. For technical questions, please use Stack Overflow .

Report general issues with App Actions features or make suggestions for additional built-in intents through our public issue tracker.

References

Releases

No releases published

Packages

No packages published

Languages

- "漢字路" 한글한자자동변환 서비스는 교육부 고전문헌국역지원사업의 지원으로 구축되었습니다.
- "漢字路" 한글한자자동변환 서비스는 전통문화연구회 "울산대학교한국어처리연구실 옥철영(IT융합전공)교수팀"에서 개발한 한글한자자동변환기를 바탕하여 지속적으로 공동 연구 개발하고 있는 서비스입니다.
- 현재 고유명사(인명, 지명등)을 비롯한 여러 변환오류가 있으며 이를 해결하고자 많은 연구 개발을 진행하고자 하고 있습니다. 이를 인지하시고 다른 곳에서 인용시 한자 변환 결과를 한번 더 검토하시고 사용해 주시기 바랍니다.
- 변환오류 및 건의,문의사항은 juntong@juntong.or.kr로 메일로 보내주시면 감사하겠습니다. .
Copyright ⓒ 2020 By '전통문화연구회(傳統文化硏究會)' All Rights reserved.
 한국   대만   중국   일본