B4A Library Google Analytics v4 library

Status
Not open for further replies.
Google Analytics V4: https://developers.google.com/analytics/devguides/collection/android/v4/

The instructions were updated to reflect V4 changes. Note that this library will only work with B4A v3.82+.

Setup instructions:
- Download Google Play Services from Android SDK Manager and copy google-play-services.jar to the additional libraries folder.
- Create a Mobile App Analytics account: https://support.google.com/analytics/answer/1042508

The tracker is configured with an XML file. You should create a file with the following text named analytics.xml and put it under Objects\res\xml (create this folder if needed):

Make sure to set this file to be read-only. Otherwise the IDE will delete it during compilation.

You should declare a single AnalyticsTracker in Sub Process_Globals of your main module (or other module). The single tracker should be used from all modules.
B4X:
Sub Process_Globals
   Public tracker As AnalyticsTracker
End Sub

Sub Globals

End Sub

Sub Activity_Create(FirstTime As Boolean)
   If FirstTime Then
     tracker.Initialize
   End If
   tracker.SendScreenView("Main Activity")
End Sub

Other implemented methods: TrackEvent, SendTransaction, SendTiming and SendProduct. Note that you can pass empty strings for optional parameters.
 

Attachments

  • AnalyticsV4.zip
    3.5 KB · Views: 1,031
Last edited:

Ratna Fang

Member
Licensed User
Longtime User
sorry, i don't get the point.
do you mean i just need to declare once in global for every activity, then put tracker.start in activity_resume and tracker.stop in activity.pause?
 

Inman

Well-Known Member
Licensed User
Longtime User
Just now I ran into an issue with this Analytics library. It was working fine till now. But today I noticed that I was using the old version of Admob library (1.x) which will be discontinued in August 2014. So I switched to version 2.0 based on the instructions given here. Now I am getting an error during compilation. How can I fix this?

B4X:
Parsing code.                          0.10
Compiling code.                        0.09
Compiling layouts code.                0.00
Generating R file.                      Error
res\values\analytics.xml:5: error: Resource at ga_trackingId appears in overlay but not in the base package; use <add-resource> to add.
res\values\analytics.xml:8: error: Resource at ga_autoActivityTracking appears in overlay but not in the base package; use <add-resource> to add.
res\values\analytics.xml:11: error: Resource at ga_reportUncaughtExceptions appears in overlay but not in the base package; use <add-resource> to add.
res\values\analytics.xml:13: error: Resource at ga_debug appears in overlay but not in the base package; use <add-resource> to add.
 

Inman

Well-Known Member
Licensed User
Longtime User
No I am using 3.20. Could that be the problem? I normally don't upgrade B4A in the middle of a project.
 

Inman

Well-Known Member
Licensed User
Longtime User
You are right. Works perfectly in 3.50. Sorry for the confusion.
 

GMan

Well-Known Member
Licensed User
Longtime User
Great Lib - works also with 2.71
 

Douglas Farias

Expert
Licensed User
Longtime User
ty erel *-* i cant wait to google+ lib *-*
 

Douglas Farias

Expert
Licensed User
Longtime User
why this error on the xml?

is correct on the res folder values normal

can is my b4a version?
3.20
B4X:
Parsing code.                          0.03
Compiling code.                        0.13
Compiling layouts code.                0.02
Generating R file.                      Error
res\values\analytics.xml:4: error: Resource at ga_trackingId appears in overlay but not in the base package; use <add-resource> to add.
res\values\analytics.xml:6: error: Resource at ga_autoActivityTracking appears in overlay but not in the base package; use <add-resource> to add.
res\values\analytics.xml:8: error: Resource at ga_reportUncaughtExceptions appears in overlay but not in the base package; use <add-resource> to add.
res\values\analytics.xml:10: error: Resource at ga_logLevel appears in overlay but not in the base package; use <add-resource> to add.
 

GMan

Well-Known Member
Licensed User
Longtime User
Are you using AdMob library as well? If yes then it will only work with B4A v3.5+
I am using AdMob, too - and works with 2.71
 

Douglas Farias

Expert
Licensed User
Longtime User
works fine now with b4a 3.8 and admob 2.0 perfect
 

MMORETTI964

Member
Licensed User
Longtime User
Hi, I have a strange issue with analytics.
We've followed all instructions (jar, activity_resume and activity_restart, analytics.xml with a copy of sample with our ID analytics code).
It works perfect when I send programmatically some event with TrackEvent & Dispatch.
In my console I can see in RealTime where is the user and the event sent "manually".

But when I crash my application I can't see any crashreport in analytics console.
I need to make some step to get crashreport works?
The crash is handled internally in some way by B4A and I need some code to report it to analytics or it should work automatically?
Some hints?

Thank you in advance.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…