title | description | created | updated |
---|---|---|---|
Google Analytics |
Google Analytics lets you measure your end user interactions on your websites and mobile apps. Google Analytics records all interactions and provides meaningful insights. |
2019-10-25 |
2019-10-25 |
Google Analytics lets you measure your end user interactions on your websites and mobile apps. Google Analytics records all interactions and provides meaningful insights.
- Web
- Android
- iOS
Google analytics can be added to web applications by including the following script in head tag.
<!-- Google Analytics-->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-xxxxx-x', 'auto');
ga('send', 'pageview');
</script>
dependencies {
classpath 'com.google.gms:google-services:3.0.0'
}
dependencies {
compile 'com.google.android.gms:play-services-analytics:10.2.4'
}
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="ga_trackingId" translatable="false">UA-xxxxx-x</string>
</resources>
package com.foo;
import android.app.Application;
import com.google.android.gms.analytics.GoogleAnalytics;
import com.google.android.gms.analytics.Tracker;
public class AnalyticsApplication extends Application {
private static GoogleAnalytics googleAnalytics;
private static Tracker tracker;
@Override
public void onCreate() {
super.onCreate();
googleAnalytics = GoogleAnalytics.getInstance(this);
}
synchronized public Tracker getDefaultTracker() {
if (tracker == null) {
tracker = googleAnalytics.newTracker(R.xml.global_tracker);
}
return tracker;
}
}
AnalyticsApplication application = (AnalyticsApplication) getApplication();
tracker = application.getDefaultTracker();
tracker.setScreenName("HomePage");
tracker.send(new HitBuilders.ScreenViewBuilder().build());