UpendraSingh / analytics-issues

Automatically exported from code.google.com/p/analytics-issues
0 stars 0 forks source link

example demo does not work #888

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
the example given at 
https://developers.google.com/analytics/devguides/collection/android/v4/

DOES. NOT. WORK.

I'm using AS 1.5.1 with the most recent versions of the libraries, but I CANNOT 
get the example to run. (Samsung S4 mini, 4.2.2)

First of all, the Gradle thing must be updated from 2.8 to 2.10.

I did *NOT* use the JSON approach, but just filled in the ga_trackingId 
property in the correct XML file:

manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="x.tracktest">

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>

</manifest>

gradle:
// Top-level build file where you can add configuration options common to all 
sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'
        classpath 'com.google.gms:google-services:2.0.0-alpha6'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

more gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "x.tracktest"
        minSdkVersion 10
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.google.android.gms:play-services-analytics:8.4.0'
}

xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <ga_trackingId>xx-xxx</ga_trackingId>
    <ga_dispatchPeriod>30</ga_dispatchPeriod>

</resources>

activity:

package x.tracktest;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.google.android.gms.analytics.GoogleAnalytics;
import com.google.android.gms.analytics.HitBuilders;
import com.google.android.gms.analytics.Tracker;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
        Tracker mTracker = analytics.newTracker(R.xml.analytics);
        mTracker.send(new HitBuilders.EventBuilder().setCategory("cat").setAction("action").build());
    }
}

Note that the "web wizard" that allows to download a JSON file has another bug: 
it does not allow me to select the correct account (I have TWO analytics 
accounts).

Next, there is NO reaction coming from the analytics console.

Maybe - if that's the case - the documentation should state that no immediate 
real-time feedback is possible, but only after X hours?

Original issue reported on code.google.com by alexande...@gmail.com on 23 Feb 2016 at 5:12

GoogleCodeExporter commented 8 years ago
looks like 

        <service android:name="com.google.android.gms.analytics.AnalyticsService"
            android:enabled="true"
            android:exported="false"/>
was the missing part.

(also, I got rid of the XML file, the parameter was wrong anyway)

but the whole concept is BADLY documented. VERY BADLY.

Original comment by alexande...@gmail.com on 23 Feb 2016 at 6:44

GoogleCodeExporter commented 8 years ago
Thanks for the report.  We'll look into it.

Original comment by t...@google.com on 24 Feb 2016 at 6:33

GoogleCodeExporter commented 8 years ago

Original comment by mcoh...@google.com on 25 Feb 2016 at 4:02

GoogleCodeExporter commented 8 years ago
The line

<ga_trackingId>xx-xxx</ga_trackingId>

should be:

<string name="ga_trackingId" translatable="false">xx-xxx</string>

The AnalyticsService Android Manifest declaration may be required for use on 
non-Google Play devices.

Original comment by t...@google.com on 26 Feb 2016 at 11:23