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
19 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,015 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,015 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,015 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,015 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,015 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,015 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,015 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,015 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,015 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_controls]
[/topic_controls]



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