GA追踪代码详解

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 Begin



Getting Started
    1. Updating AndroidManifest.xml
    2. Adding EasyTracker methods
    3. Creating your analytics.xml file



Next 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 Analytics
A new Google Analytics app property and view (profile).

Getting Started

There are three steps to getting started with the SDK:

Update AndroidManifest.xml
Add EasyTracker methods
Create your analytics.xml file

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

App installations
Active users and demographics
Screens and user engagement
Crashes 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:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值