简体   繁体   中英

Implementing google analytics for android app

How to Implement Google Analytics for the android app?

(I need basic Code I Searched a lot of Websites But I didn't understand please help me)

Thanks in advance..

https://developers.google.com/analytics/devguides/collection/android/v3/ this link will guide you.

http://dl.google.com/googleanalyticsservices/GoogleAnalyticsServicesAndroid_3.02.zip download the jar for analytics from this link. put in in libs.

https://www.google.com/analytics/web/ and use create an account for analytics at this location. and create a new app in it. use its analytics app id as below.

and use below code in each of your activity.

public void TrackEvent(String category, String action, String label, Long value)
        {
            // TODO Auto-generated method stub
            EasyTracker easyTracker = EasyTracker.getInstance(this);

            easyTracker.send(MapBuilder.createEvent(category, action, label, value).build());
        }

    public void onStart()
        {
            super.onStart();
            EasyTracker.getInstance(this).activityStart(this);
            GoogleAnalytics.getInstance(this).getTracker(your_Analytics_ID);
        }

    @Override
    protected void onStop()
        {
            // TODO Auto-generated method stub
            super.onStop();
            EasyTracker.getInstance(this).activityStop(this);
        }

use trackEvent method to track your all events.

This answer is completely based on v3, but currently v4 can be used using google play services library.

OK. here is the trick.

create an xml file analytics.xml in values folder.

<resources>

<!-- Replace placeholder ID with your tracking ID -->
<string name="ga_trackingId">google_analytics_id</string>

<!-- Enable automatic activity tracking -->
<bool name="ga_autoActivityTracking">true</bool>

<!-- Enable automatic exception tracking -->
<bool name="ga_reportUncaughtExceptions">true</bool>

</resources>

I hope this helps u.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM