开发者控制台
感谢您的访问。此页面目前仅提供英语版本。我们正在开发中文版本。谢谢您的理解。

Google Analytics Component

 IV: Add Components for More Functionality

The Google Analytics Component allows you to gather analytics from your Android app using Google Analytics. You can learn more about the analytics service by going to Google Analytics.

Configuring the component requires you to set up a google-services.json file that you generate from Google Analytics. You then match up dimensions and metrics indexes between Google Analytics and the component in Fire App Builder. You also need to set up custom reports that contain the dimensions and metrics you want.

To configure the Google Analytics Component, complete each of the following sections.

Step 1. Configure the Google Analytics Component

  1. Load the Google Analytics component into your app. See Add or Remove a Component for details about how to load a component into your app.

    Be sure to remove any other analytics components that are loaded in your app (such as Crashlytics, FlurryAnalyticsComponent, OmnitureAnalyticsComponent, ComScoreAnalyticsComponent, or LoggerAnalyticsComponent). See Add or Remove a Component for details.

  2. Click the Sync Gradle button .

Step 2. Set Up the google-services.json File

Google Analytics packages all of your analytics settings into a google-services.json file. After you generate and download this file, you will place it in the Google Analytics Component folder.

  1. Sign in to your Google account.
  2. On the Google Analytics site, go to Add Analytics to Your Android App.
  3. In the Get a configuration file section, click Get a Configuration File.
  4. Enter an App name and an Android package name.
    • For the App name, type the name of your app.
    • For the Android package name, use the package name in the Google Analytics Component's AndroidManifest.xml file: com.amazon.analytics.google.
  5. Click Continue to choose and configure services.

    Although the screen says "Select which Google services you'd like to add to your app below," only Analytics is available for integration.

  6. Click Continue to generate configuration files.
  7. Click Download google-services.json and download the JSON file.
  8. Move the google-services.json file into your GoogleAnalyticsComponent folder. (If you're in the Android view, switch to the Project view to see this file.)

Step 3. Set Up Dimensions

In this step you will set up dimensions in your app that correspond with dimensions that you set up in Google Analytics.

According to Google Analytics' documentation, "Dimensions are attributes of your data. For example, the dimension City indicates the city, for example, 'Paris' or 'Boston', from which a session originates. The dimension Page indicates the URL of a page that is viewed."

To set up dimensions:

  1. In your app, expand GoogleAnalyticsComponent > assets > configurations and open the GoogleCustomDimensionsTags.json file.

    {
      "ATTRIBUTE_PLATFORM": "1",
      "ATTRIBUTE_SEARCH_TERM": "2",
      "ATTRIBUTE_ERROR_MSG": "3",
      "ATTRIBUTE_PLAY_SOURCE": "4",
      "ATTRIBUTE_PURCHASE_RESULT": "5",
      "ATTRIBUTE_PURCHASE_SKU": "6",
      "ATTRIBUTE_TITLE": "7",
      "ATTRIBUTE_SUBTITLE": "8",
      "ATTRIBUTE_VIDEO_TYPE": "9",
      "ATTRIBUTE_PURCHASE_TYPE": "10",
      "ATTRIBUTE_PURCHASE_SOURCE": "11",
      "ATTRIBUTE_APP_NAME": "12",
      "ATTRIBUTE_APP_AUTHENTICATION_SOURCE": "13",
      "ATTRIBUTE_LOGIN_FAILURE_REASON": "14",
      "ATTRIBUTE_LOGOUT_FAILURE_REASON": "15",
      "ATTRIBUTE_AIRDATE": "16",
      "ATTRIBUTE_PUBLISHER_NAME": "17",
      "ATTRIBUTE_APP_AUTHENTICATION_STATUS": "18",
      "ATTRIBUTE_VIDEO_ID": "19",
      "ATTRIBUTE_CONTENT_AVAILABLE": "20",
      "ATTRIBUTE_REQUEST_SOURCE": "21"
    }
    
  2. Copy the file's contents and create a similarly named file in your app's assets > configurations folder. (Any files in your app will overwrite similar files in the component. This will help you apply updates to Fire App Builder later on.)

    You will be creating dimensions in Google Analytics that correspond with the dimensions and indexes here. (You don't need to do anything with the code here just yet. Just leave the file open to adjust later.)

  3. Sign in to your Google Analytics Dashboard.
  4. Click Admin in the lower-left corner.
  5. In the Property column (the middle column), click Custom Definitions > Custom Dimensions.

  6. Click the New Custom Dimension button.

  7. Type a friendly name for the first dimension. For example, type "Platform" instead of "ATTRIBUTE_PLATFORM".
  8. Leave the Scope as Hit (the default).
  9. Leave Active check box selected.
  10. Click Create.

  11. Click Done.
  12. Repeat this process until you have created a custom dimension for all of the dimensions you want to track (up to 20).

  13. In the GoogleCustomDimensionsTags.json file (inside your app's assets > configurations folder), change the index numbers to correspond with the auto-created dimension index numbers (the column is highlighted in yellow in the screenshot below) in your Google Analytics Dashboard.

    (Since you can't customize the index values in Google Analytics, you have to make the index values in the component match up with the index values Google creates.)

    {
      "ATTRIBUTE_PLATFORM": "1",
      "ATTRIBUTE_SEARCH_TERM": "2",
      "ATTRIBUTE_ERROR_MSG": "3",
      "ATTRIBUTE_PLAY_SOURCE": "4",
      "ATTRIBUTE_PURCHASE_RESULT": "5",
      "ATTRIBUTE_PURCHASE_SKU": "6",
      "ATTRIBUTE_TITLE": "7",
      "ATTRIBUTE_SUBTITLE": "8",
      "ATTRIBUTE_VIDEO_TYPE": "9",
      "ATTRIBUTE_PURCHASE_TYPE": "10",
      "ATTRIBUTE_PURCHASE_SOURCE": "11",
      "ATTRIBUTE_APP_NAME": "12",
      "ATTRIBUTE_APP_AUTHENTICATION_SOURCE": "13",
      "ATTRIBUTE_LOGIN_FAILURE_REASON": "14",
      "ATTRIBUTE_LOGOUT_FAILURE_REASON": "15",
      "ATTRIBUTE_AIRDATE": "16",
      "ATTRIBUTE_PUBLISHER_NAME": "17",
      "ATTRIBUTE_APP_AUTHENTICATION_STATUS": "18",
      "ATTRIBUTE_VIDEO_ID": "19",
      "ATTRIBUTE_CONTENT_AVAILABLE": "20"
    }
    

    Unless you created the dimensions in Google in the exact same order, it's likely that your index values will be somewhat different. Just make sure each dimension you created in Google Analytics (for example, Error Message, 3) corresponds with the dimensions and indexes in your component (for example, "ATTRIBUTE_ERROR_MSG": "3").

Step 4. Set Up Metric Indexes

In this section, you'll do the same thing you did in the previous section but with metric indexes. According to Google Analytics documentation, "Metrics are quantitative measurements. The metric Sessions is the total number of sessions. The metric Pages/Session is the average number of pages viewed per session."

  1. Expand GoogleAnalyticsComponent > assets > configurations and open the GoogleCustomMetricTags.json file.

    {
      "ATTRIBUTE_AD_SECONDS_WATCHED": "1",
      "ATTRIBUTE_VIDEO_SECONDS_WATCHED": "2",
      "ATTRIBUTE_VIDEO_CURRENT_POSITION": "3",
      "ATTRIBUTE_AD_ID": "4",
      "ATTRIBUTE_VIDEO_DURATION": "11",
      "ATTRIBUTE_EXPIRED_RECOMMENDATIONS_COUNT": "12",
      "ATTRIBUTE_RECOMMENDATION_ID": "13"
    }
    
  2. Copy the file's contents and create a similarly named file in your app's assets > configurations folder.

    Similar to dimensions, you will be creating metrics in Google Analytics that correspond with the metrics and indexes here. (You don't need to do anything with the code here just yet. Just leave the file open to adjust later.)

  3. Sign in to your Google Analytics Dashboard.
  4. Click Admin on the top navigation row.
  5. In the Property column (the middle), click Custom Definitions > Custom Metrics.
  6. Click the New Custom Metric button.

  7. Type a friendly name for the first metric. For example, type "Ad Seconds Watched" instead of "ATTRIBUTE_VIDEO_SECONDS_WATCHED".
  8. Leave the other values (Scope, Formatting Type, Minimum Value, Maximum Value, and Active) at the defaults unless you specifically want to adjust these values.
  9. Click Create.
  10. Click Done.
  11. Repeat this process with the other metrics for all the metrics you want to track.

  12. In the GoogleCustomMetricTags.json file (inside your app's assets > configurations folder), change the metrics index numbers to correspond with the auto-created metric index numbers in your Google Analytics Dashboard.

    (Since you can't customize the index values in Google Analytics, you have to make the index values in the component match up with the index values Google creates.)

Step 5. Set Up Reports

The final step is to create a report based on the dimensions and metrics in the component.

  1. In Google Analytics, click Customization.
  2. Click the New Custom Report button.
  3. Give your custom report a Title.
  4. In the Dimensions section, click + add dimension, expand Custom Dimensions, and select the dimensions you want.
  5. In the Metrics Groups section, click + add metric, expand Custom Metrics, and select the metrics you want.

  6. Make any other adjustments to your report, and click Save.

Step 6. Verify Everything Is Working

You can verify the Google integration by doing the following:

  1. In Android Studio, launch your app.
  2. In Google Analytics, click Reporting and then go to Real-Time > Overview.

    You should see an active user.


Last updated: Apr 06, 2017