GA追踪代码详解

来源:互联网 发布:淘宝卖家能知道买家 编辑:程序博客网 时间:2024/06/06 00:18

GA追踪代码详解

GA的作用就是获取你的应用程序的用户使用量,用户的点击行为,事件,地点等,还可以统计应用崩溃的详情等。
首先进入谷歌www.google.com/analytics/的GA网址,然后注册一个账号,里面会有android和ios的接入指南:
https://developers.google.com/analytics/devguides/collection/android/v3/
https://developers.google.com/analytics/devguides/collection/ios/v3/
下面的这个是使用的API:
https://developers.google.com/analytics/devguides/collection/android/v3/#manifest
按照里面的步骤一步一步来就行了。需要注意的一点就是每个activity都要配置API中的onstart和onstop方法。
还需要在API指引的地方下载一个libGoogleAnalyticsServices.jar,引入工程就可以了。

下面是API的具体内容:
Google Analytics SDK for Android v3 (Beta) - Getting Started

This document describes how to get started using the Google Analytics SDK for Android v3.
Migrating from v1 or v2? Check out our Migration Guide to get started using v3.

Before You BeginGetting Started    1. Updating AndroidManifest.xml    2. Adding EasyTracker methods    3. Creating your analytics.xml fileNext steps

Before you Begin

Before implementing the SDK, make sure you have the following:

Android developer SDK (available for Windows, Mac OS X, and Linux)Google Analytics SDK for Android v3 (with libGoogleAnalyticsServices.jar included in your project's /libs directory and build path)An Android app that you can use to implement the Google AnalyticsA new Google Analytics app property and view (profile).

Getting Started

There are three steps to getting started with the SDK:

Update AndroidManifest.xmlAdd EasyTracker methodsCreate your analytics.xml file

After completing these steps, you’ll be able to measure the following with Google Analytics:

App installationsActive users and demographicsScreens and user engagementCrashes and exceptions
  1. Updating AndroidManifest.xml

Update your AndroidManifest.xmle file by adding the following permissions:


  1. Adding EasyTracker methods

Add the send methods to the onStart() and onStop() methods of each of your Activities as in the following example:

package com.example.app;

import android.app.Activity;

import com.google.analytics.tracking.android.EasyTracker;

/**
* An example Activity using Google Analytics and EasyTracker.
*/
public class myTrackedActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}

@Override
public void onStart() {
super.onStart();
… // The rest of your onStart() code.
EasyTracker.getInstance(this).activityStart(this); // Add this method.
}

@Override
public void onStop() {
super.onStop();
… // The rest of your onStop() code.
EasyTracker.getInstance(this).activityStop(this); // Add this method.
}
}

  1. Creating your analytics.xml file

When you use EasyTracker, global configuration settings are managed using resources defined in XML. Create a file called analytics.xml in your project’sres/values directory and add the following resources:

0 0
原创粉丝点击