A Fuse Powered Company

Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Release: Google Analytics module
Started by jonjonsson Aug 24 2014 12:14 AM

* * * * * 1 votes
24 replies to this topic
google analytics analytics
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

jonjonsson

[GLOBAL: userInfoPane.html]
jonjonsson
  • Pro
  • PipPipPipPipPipPip
  • 1,027 posts
  • Jedi

I made a module for Google Analytics Mobile App Tracking that I thought I would share. Some of the things you can track with this module: events, scenes, sessions, purchases, timings, social events and errors. It also has some basic offline support.

 
I have not tested this thing to the max on many devices, please report any issues and any improvement ideas you may have.
 

Its not using the native SDKs of iOS and Android but instead sends the payloads to Google via POST. From what I can tell there is not much downside to this, but then again I have never tried the native method.

 

There was one hurdle that makes this a little hacky. The network.request() function on iOS does not send a user agent that Google can determine the device type from (discussed here). To overcome this the module will create a webview on iOS devices (off screen when launched) and use a local html file with some javascript to get the correct user agent and then resend any events it may have missed during that process. 

 

Code share: http://code.coronalabs.com/code/google-analytics-module

Repo: https://bitbucket.org/Jonjonsson/google-analytics-for-corona-sdk/



[TOPIC: post.html]
#2

hgbrian

[GLOBAL: userInfoPane.html]
hgbrian
  • Pro
  • PipPipPipPipPipPip
  • 94 posts
  • Jedi

I just started using this and it's fantastic. Thanks Jon!



[TOPIC: post.html]
#3

jonjonsson

[GLOBAL: userInfoPane.html]
jonjonsson
  • Pro
  • PipPipPipPipPipPip
  • 1,027 posts
  • Jedi

Awsome! Thanks :)

 

I have gone live with it and it works well except there are some mobile devices not sending user agent.

 

oN5ttOY.png

 

So I'm going to try the user agent work around in all cases, not only iOS and see if it will be better and update the code if so.



[TOPIC: post.html]
#4

hiccastudios

[GLOBAL: userInfoPane.html]
hiccastudios
  • Starter
  • PipPip
  • 28 posts
  • Member

oh well. thats why my device is not working.

is there any patch yet ?



[TOPIC: post.html]
#5

jonjonsson

[GLOBAL: userInfoPane.html]
jonjonsson
  • Pro
  • PipPipPipPipPipPip
  • 1,027 posts
  • Jedi

oh well. thats why my device is not working.

is there any patch yet ?

 

No, I tried user agent work around for Android as well and still have missing device names. The biggest offender is HTC One according to my stats (but not all version though).

 

I added secondary dimension variable with the Device name from Corona so I can see what these (no set) devices are.

 

sessionParams = {cd1 = system.getInfo("model")}
 
Here are the offenders:
 

 

1705B 4.1.1

306SH 4.4.2
A0001 4.4.4
A5Smiley 4.4.2
AllviewAX2Frenzy 4.0.4
D6653 4.4.4
FS-M787S 4.0.4
Full Android on Crespo4G 4.1.1
GT-I9507 4.3
HTC One_M8 4.4.2
HTC One_M8 4.4.3
HTC One_M8 4.4.4
HTC One_M8 5.0
HTC One_M8 5.0.1
HTC6515LVW 4.4.2
Informer 701 4.0.3
iris400Q 4.4.2
iris700 4.4.2
Lenovo A706_ROW 4.1.2
LG-D852 4.4.2
LGL39C 4.1.2
LGLS620 4.4.2
LGLS660 4.4.2
LGLS990 4.4.2
Micromax A082 4.4.2
MyPhone Agua Rain 3G 4.2.2
Nexus 7 L
Nexus 9 5.0
NX008HD8G 4.1.1
One 4.4.4
Pacific800i 4.2.2
QTAQZ3 4.4.2
Samsung Galaxy S3 - 4.3 - API 18 - 720x1280 4.3
SM-G313HZ 4.4.2
SM-N910F 4.4.4
SM-N910P 4.4.4
SM-N910T 4.4.4
Smartfren Andromax AD6B1H 4.4.2
Studio 5.0LTE 4.3
Telenor Smart Pro 2 4.1.1
TP7-1000DC 4.1.1
XT1039 4.4.4
XT1254 4.4.4
XT830C 4.4.4

 



[TOPIC: post.html]
#6

hiccastudios

[GLOBAL: userInfoPane.html]
hiccastudios
  • Starter
  • PipPip
  • 28 posts
  • Member

Thanks for the update jonjonsson :)

 

my device is Nexus 5.

so meanwhile i use other device to test it ?

 

thanks



[TOPIC: post.html]
#7

jonjonsson

[GLOBAL: userInfoPane.html]
jonjonsson
  • Pro
  • PipPipPipPipPipPip
  • 1,027 posts
  • Jedi

Ah ok, we are not talking about the same thing :)

 

The module works with ALL devices, even simulator. Just the device name is not reported in few cases.

 

If you are having problem getting it to work start with simulator only and a test tracking ID. Then go to Google Analytics for your test ID and click "Real time" and you should see a connection. If  not something is misconfigured.



[TOPIC: post.html]
#8

hiccastudios

[GLOBAL: userInfoPane.html]
hiccastudios
  • Starter
  • PipPip
  • 28 posts
  • Member

Oh .. sorry. my bad. so its about reporting ?

 

i have check in simulator, all worked, but when i test in analytic realtime, no device active. thats why im asking.

 

heres my setting. im using composer

 

-----------analytic google
ga = require("GoogleAnalytics.ga")
ga.init({ -- Only initialize once, not in every file
    isLive = true, -- REQUIRED
productionTrackingID = "UA-xxxxxx-2",
    testTrackingID = "UA-xxxxxxx-2", -- REQUIRED Tracking ID from Google
    debug = true, -- Recomended when starting
})
 
and heres event tracker in other lua files
 
function onmoreappstouch( self, event )
if event.phase == "ended" or event.phase == "cancelled" then  
ga.enterScene("more series")
audio.play( slide_audio, { channel=0, loops=0, fadein=100 } ) 
composer.gotoScene( "moreapps", { effect = "slideLeft", time = 1200 } )
 
else
return true -- indicates successful touch
end
end


[TOPIC: post.html]
#9

jonjonsson

[GLOBAL: userInfoPane.html]
jonjonsson
  • Pro
  • PipPipPipPipPipPip
  • 1,027 posts
  • Jedi

Because you have isLive = true the device will use the productionTrackingID and you are probably checking the testTrackingID in Google Analytics.  

 

It works for you in the simulator because simulator ignores isLive. Simulator is only used for developing and always uses testTrackingID.

 

So for now, put isLive = false and just focus on the testTrackingID. It will work on device also.

 

When you are close to going live, create your productionTrackingID, change isLive = true and test on device. That way your test data is not mixed with live data in Google Analytics.



[TOPIC: post.html]
#10

hiccastudios

[GLOBAL: userInfoPane.html]
hiccastudios
  • Starter
  • PipPip
  • 28 posts
  • Member

I already use false in previous version and its not working. That's why I try to switch in true. Or is there any thing I missed in Google setup?

[TOPIC: post.html]
#11

jonjonsson

[GLOBAL: userInfoPane.html]
jonjonsson
  • Pro
  • PipPipPipPipPipPip
  • 1,027 posts
  • Jedi

If you see it working in simulator then probably your setup is fine.

 

Have you checked device logs for errors?



[TOPIC: post.html]
#12

hiccastudios

[GLOBAL: userInfoPane.html]
hiccastudios
  • Starter
  • PipPip
  • 28 posts
  • Member

Not yet. But no error and perfectly work in simulator. Just not showed up in the analytics

[TOPIC: post.html]
#13

hiccastudios

[GLOBAL: userInfoPane.html]
hiccastudios
  • Starter
  • PipPip
  • 28 posts
  • Member

can we check the traffic using simulator only ?



[TOPIC: post.html]
#14

hiccastudios

[GLOBAL: userInfoPane.html]
hiccastudios
  • Starter
  • PipPip
  • 28 posts
  • Member

oh, its works now.

i tested in 2 device and its works.

 

so strage. thanks for our support :)



[TOPIC: post.html]
#15

jonjonsson

[GLOBAL: userInfoPane.html]
jonjonsson
  • Pro
  • PipPipPipPipPipPip
  • 1,027 posts
  • Jedi


[TOPIC: post.html]
#16

hiccastudios

[GLOBAL: userInfoPane.html]
hiccastudios
  • Starter
  • PipPip
  • 28 posts
  • Member

Hi,

 

i wondering to enable Display Advertising features for Android. 

is that posible ?

 

https://support.google.com/analytics/answer/2444872?hl=en&utm_id=ad

 

it said to add this lines :

 

// Get tracker.
Tracker t = ((AnalyticsSampleApp) getActivity().getApplication()).getTracker(
TrackerName.APP_TRACKER);

// Enable Display Features.
t.enableAdvertisingIdCollection(true);



[TOPIC: post.html]
#17

jonjonsson

[GLOBAL: userInfoPane.html]
jonjonsson
  • Pro
  • PipPipPipPipPipPip
  • 1,027 posts
  • Jedi


[TOPIC: post.html]
#18

hiccastudios

[GLOBAL: userInfoPane.html]
hiccastudios
  • Starter
  • PipPip
  • 28 posts
  • Member

i see. because it said its needed in order to show demographic and interest report. :)

 

https://www.google.com/analytics/web/#report/app-visitors-demographics-overview/a48956626w91244224p94950130/

 

thanks



[TOPIC: post.html]
#19

jonjonsson

[GLOBAL: userInfoPane.html]
jonjonsson
  • Pro
  • PipPipPipPipPipPip
  • 1,027 posts
  • Jedi

You probably need native access for that (enterprise Corona).

 

I'm guessing you probably need hundreds of thousands of users to get any meaningful age/gender/hobby/etc data from Google since it won't work for all users. 



[TOPIC: post.html]
#20

hiccastudios

[GLOBAL: userInfoPane.html]
hiccastudios
  • Starter
  • PipPip
  • 28 posts
  • Member

Yes i think.

Thanks Jonjonsson :D



[TOPIC: post.html]
#21

joedavinci

[GLOBAL: userInfoPane.html]
joedavinci
  • Starter
  • PipPipPip
  • 30 posts
  • Advanced Member

--- EDIT : this post and question is no longer valid, data shows up now.. seems like it doesn't track anything from windows simulator, but once I ran it on any device, it started showing up in Analytics dashboard ---

 

Hi Jon,

 

I created my account on google analytics yesterday (a Mobile App type property), and today I'm trying to get it working in my app using your module.

 

So far however, I've had no luck: no matter what I do, the google analytics console shows me "0 sessions" in Realtime tracking overview.

 

Is this an error, should it work? Or does your module not give GA the realtime data and I'm just over-concerned?  From other apps (fully native professional apps, not corona based) I know the realtime data are usually displayed within 5-10 seconds as soon as I run the app

 

Here's the  bit of your code I have in my main.lua (I obviously replaced the tracking codes with Xs, but in my code I have the right IDs - checked it about a hundred times.

print("\n\n---------START GOOGLE ANALYTICS PRINTOUT-----------")

local ga = require("GoogleAnalytics.ga")

ga.init({
    isLive = false, 
    testTrackingID = "UA-xxxxxxxx-1",  -- <-- Replace with your tracking code. If code is wrong it fails silently.
    productionTrackingID = "UA-xxxxxxxx-2",  -- <-- Replace with your tracking code. If code is wrong it fails silently.
    debug = true,
    appName = "TSC Calc Test",
    appVersion = "1.1.4",
    appID = "com.mcxondev.tsccalc.test",
    clientID = "CoronaSimulator-" .. math.random( 1,100000)
})

ga.enterScene("Main Scene (start app)")

print("---------END GOOGLE ANALYTICS PRINTOUT-----------\n\n")

I'm also attaching my terminal output screenshot and the sad view of the google analytics console.

 

 

Any tips on what am I doing wrong?

 

I appreciate any advice you can give me.

 

Thank you.

Attached Thumbnails

  • terminal_output.png
  • ga-realtime overview.png


[TOPIC: post.html]
#22

jonjonsson

[GLOBAL: userInfoPane.html]
jonjonsson
  • Pro
  • PipPipPipPipPipPip
  • 1,027 posts
  • Jedi

Hi Joe,

 

yes it only takes a couple of secs to show up in the real time stats.

 

To debug this you can copy the URL you see in the debug console and use it in a browser, it should show up as a hit in real time stats.

 

Paste a copy of the URL here and I'll test it with my test ID as well.



[TOPIC: post.html]
#23

joedavinci

[GLOBAL: userInfoPane.html]
joedavinci
  • Starter
  • PipPipPip
  • 30 posts
  • Advanced Member

Well no worries, like I said in the edit on top of my post - it only doesn't work in the windows simulator, but when I ran the same build on a device, the analytics are showing up in realtime.

 

... except on my older HTC Desire S phone :)  

I Don't know why, I tested 7 different devices, and every single one of them reports ok, but the HTC phone I have with a custom (but HTC based) ROM doesn't seem to send anything - or at least it doesn't show up in analytics at all, realtime, or the historical (previous day for now)

I'm trying to get some more HTC devices to try if it's just this one, or if it's a HTC linked problem.

 

weird though..



[TOPIC: post.html]
#24

jonjonsson

[GLOBAL: userInfoPane.html]
jonjonsson
  • Pro
  • PipPipPipPipPipPip
  • 1,027 posts
  • Jedi

That is weird! It's just a POST network request. Very basic stuff, should just work everywhere one would think :)



[TOPIC: post.html]
#25

fosfor

[GLOBAL: userInfoPane.html]
fosfor
  • Pro
  • PipPipPip
  • 35 posts
  • Advanced Member

This is great, thanks jonjonsson!

 

My client is asking me to implement Google Tag Manager tracking into a corona app. Any ideas on how that could be done?

 

http://getdelve.com/2013/10/how-to-set-up-google-analytics-through-google-tag-manager-and-the-data-layer/




[topic_controls]
[/topic_controls]



Also tagged with one or more of these keywords: google analytics, analytics