Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Analytics picking up wrong version number for my Android App

I am adding Google Analytics in my app. When I go to Real Time > Overview I see 1.0 under App Version. My question is where is Google Analytics getting this 1.0 number from?

enter image description here

This is how I am starting Analytics in the onCreate() of my Launcher Activity:

        analytics = GoogleAnalytics.getInstance(MainDrawerActivity.this);
        analytics.setLocalDispatchPeriod(1800);

        tracker = analytics.newTracker("UA-XXXXXX-X"); // Replace with actual tracker/property Id
        tracker.enableExceptionReporting(true);
        tracker.enableAdvertisingIdCollection(true);
        tracker.enableAutoActivityTracking(true);

My project has multiple gradle files. I am pasting them all here:

enter image description here

Here is my gradle file and also my Android Manifest: build.gradle: (for my Project: xxx...)

buildscript {
repositories {
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:1.1.3'

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

allprojects {
repositories {
    jcenter()
}
}

build.gradle: (for my Module: app)

android {
compileSdkVersion 22
buildToolsVersion "22.0.0"

defaultConfig {
    applicationId "xxx.xxx.xxx"
    minSdkVersion 16
    targetSdkVersion 22
    versionCode 58
    versionName "2.0.13"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

compileOptions {
    encoding "UTF-8"
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7
}
lintOptions {
    abortOnError false
}
}

build.gradle for Module: circularImageView (this is a library project) apply plugin: 'com.android.library'

android {
compileSdkVersion 22
buildToolsVersion "22.0.0"

defaultConfig {
    minSdkVersion 11
    targetSdkVersion 19

    versionCode 60
    versionName "2.0.14"
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }
}
}

Beginning of my Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="xxx.xxxx.xxxxxxxx"
android:installLocation="internalOnly"
android:versionCode="58"
android:versionName="2.0.13" >

<uses-sdk
    android:minSdkVersion="16"
    android:targetSdkVersion="21" />

Another point to note is that -- before the "1.0" version seen, I was in Eclipse but this is the first time I am on Android Studio but I used the Gradle Method to add Google Analytics to my account.

like image 516
user1406716 Avatar asked Jun 17 '15 17:06

user1406716


People also ask

Why is Google Analytics not accurate?

One of the biggest causes of inaccuracies within Google Analytics is a lack of information about where your visitors are coming from. And while some of that is unavoidable, you can address a large part of the problem by adding tracking information to the URLs you use in your online advertising campaigns.

How do I know if I have Google Analytics on my Android app?

If this is your first time using a Google services sample, check out the google-services repository. Open Android Studio. Select File > Open, browse to where you cloned the google-services repository, and open google-services/android/analytics .


1 Answers

It gets the version from the context that is passed to GoogleAnalytics.getInstance(context)

PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
packageInfo.versionName;

According to the documentation for PackageInfo:

The version name of this package, as specified by the tag's versionName attribute.

Also, for it to accurately get your application data, you should create the Tracker from a class extending Application

public class MyApp extends Application {
    public Tracker tracker;
    .....

    public Tracker getTracker() {
        if (tracker == null) {
            tracker = GoogleAnalytics.getInstance(this);
            .......
        }
        return tracker;
     }
}
like image 144
mattfred Avatar answered Oct 26 '22 23:10

mattfred