c#


Integrating Google Analytics with xamarin android app


I am working on an Android app using Xamarin. I have tried to follow this tutorial from Google in which they ask me to edit the build.gradle file but I don't have this file in my solution (maybe because I am in Xamarin, I don't know). So I have searched for an other tutorial especially for Xamarin user.
I have found this one and those are my code till now:
public class GAService
{
public string TrackingId = "XX-XXXXXXXX-X";
private static GoogleAnalytics GAInstance;
private static Tracker GATracker;
#region Instantiation ...
private static GAService thisRef;
private GAService()
{
}
public static GAService GetGASInstance()
{
if (thisRef == null)
thisRef = new GAService();
return thisRef;
}
#endregion
public void Initialize(Context AppContext)
{
GAInstance = GoogleAnalytics.GetInstance(AppContext.ApplicationContext);
GAInstance.SetLocalDispatchPeriod(10);
GATracker = GAInstance.NewTracker(TrackingId);
GATracker.EnableExceptionReporting(true);
GATracker.EnableAdvertisingIdCollection(true);
GATracker.EnableAutoActivityTracking(true);
}
public void Track_App_Page(String PageNameToTrack)
{
GATracker.SetScreenName(PageNameToTrack);
GATracker.Send(new HitBuilders.ScreenViewBuilder().Build());
}
public void Track_App_Event(String GAEventCategory, String EventToTrack)
{
HitBuilders.EventBuilder builder = new HitBuilders.EventBuilder();
builder.SetCategory(GAEventCategory);
builder.SetAction(EventToTrack);
builder.SetLabel("AppEvent");
GATracker.Send(builder.Build());
}
public void Track_App_Exception(String ExceptionMessageToTrack, Boolean isFatalException)
{
HitBuilders.ExceptionBuilder builder = new HitBuilders.ExceptionBuilder();
builder.SetDescription(ExceptionMessageToTrack);
builder.SetFatal(isFatalException);
GATracker.Send(builder.Build());
}
}
I am getting the same error in three places in the above code, the first is here: private static GoogleAnalytics GAInstance; which says The namescape 'GoogleAnalytics' could not be found.
The second is here:private static Tracker GATracker; saying The namescape 'Tracker' could not be found.
The third is here: HitBuilders.EventBuilder builder = new HitBuilders.EventBuilder(); saying The namescape 'HitBuilders' could not be found.
Any solutions for my problem ?
Thank you in advance
You can check out this tutorial. Specifically the first 2 points where, on Android, you will need to install the Google Play Services Analytics NuGet package to get access to those classes.
I used Google Analytics in my project (now I replaced it with Firebase Analytics), and your code is correct, exactly like mine. I don't know why you named your method parameters in upper case, for me it's a very unlucky decision, but that's a detail.
Be sure that you are using Android.Gms.Analytics and that in your packages.config there are references to GooglePlayServices.Analytics like these:
<package id="Xamarin.GooglePlayServices.Analytics" version="42.1001.0" targetFramework="monoandroid70" />
<package id="Xamarin.GooglePlayServices.Analytics.Impl" version="42.1001.0" targetFramework="monoandroid70" />

Related Links

How to get or read properties from a file in C#
Unable to Access my asp.net webservice from Android application
WebClient Post to MVC Controller From NServiceBus/Queue Service
how to iterate a list created by linq
Connecting at Phone and Laptop together automatically (dot net)
Can I get child class instance from `this` in C#?
Dispose Object Of RestRequest RestSharp?
Running CMD commands from C#
C# XAML Binding of a default with IValueConverter
DateTime losing Milliseconds
Loading multiple XDocuments, and working with its documents
Read-only interface without requiring body in abstract class?
run.bat file executing multiple files
HttpResponseMessage StringContent replacing message content
Using c# htmlagilitypack to find out the color of each text fragment
automating silverlight applet with .net reflection

Categories

HOME
redux
wifi
popover
gaussian
grid
aggregate-functions
ephesoft
box-api
cracking
wowza
aws-sdk-cpp
swift3.1
keystone
minimagick
include-path
ng-tags-input
screen-scraping
onclicklistener
oracle-golden-gate
suitescript
dynamic-memory-allocation
intermec
ilog
openvms
wit-ai
pyenv
respect-validation
android-databinding
stochastic-process
origami
tapply
superclass
head
cakephp-3.2
yank
opos
androiddesignsupport
trusted-computing
spring-social-twitter
turbolinks
transaction-isolation
shtml
python-rq
android-progressbar
dynamics-nav
sdkman
android-filterable
avrcp
polarion
eula
asp.net-2.0
quickfixn
crystal-reports-7
report-builder2.0
jsonschema2pojo
react-os
go-gin
formbuilder
system.net
parallel-port
behance-api
telerik-appbuilder
isl
pyalgotrade
django-tests
farpoint-spread
html5-filesystem
starling-framework
nvcc
scidb
myrrix
sygic
nokogiri
angularjs-select2
windows-scheduler
metapost
moonscript
django-admin-tools
pinchzoom
zend-validate
discussion-board
log-shipping
hs-err
table-valued-parameters
chromebug
webdb

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile