I am using this code in a separate file (ga.lua) to send data to Google Analytics. In the simulator it works fine, but not on device (android, tried several)
In the simulator it works fine, I can even see real time as well. I’ve used this exact same setup on other apps and theese works fine. But now I just can’t get it to work. Tried with different Analytics accounts. Same result.
I carefulle checked if any filenames differs from code (lower/uppercase) since simulator ignoers this and device doesn’t.
ga.lua:
local ga = {}; -- CALLING THE INIT FUNC WILL ATTEMPT TO LOG A GOOGLE ANALYTICS MEASUREMENT PROTOCOL EVENT IN LIEU OF THE PLUGIN -- FOR MORE INFO, SEE https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide#apptracking local track = function(pageName) local ga\_tid = "UA-XXXXXXXXX" -- YOUR GA MOBILE APP TID local appName = "IGOTTAreachthebus" -- Name of your game - w/o spaces or special chars local cd = pageName -- argument sent in function call local ga\_cid = system.getInfo("deviceID") local function networkListener(e) if e.isError then print("GA Tracking unsuccessful") else print("Tracking sent to GA...."); print(e.response); end end network.request("http://google-analytics.com/collect?v=1&tid="..ga\_tid.."&cid="..ga\_cid.."&an="..appName.."&t=appview&av=1&cd="..pageName.."","POST",networkListener) end ga.track=track return ga
main.lua:
ga = require( "ga" )
levels.lua:
ga.track("Level: " .. level)
Debug output (CMD)
I/Corona ( 4457): Tracking sent to GA.... I/Corona ( 4457): \<!DOCTYPE html\> I/Corona ( 4457): \<html lang=en\> I/Corona ( 4457): \<meta charset=utf-8\> I/Corona ( 4457): \<meta name=viewport content="initial-scale=1, minimum-scale =1, width=device-width"\> I/Corona ( 4457): \<title\>Error 400 (Bad Request)!!1\</title\> I/Corona ( 4457): \<style\> I/Corona ( 4457): \*{margin:0;padding:0}html,code{font:15px/22px arial,sans- serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-wid th:390px;min-height:180px;padding:30px 0 15px}\* \> body{background:url(//www.goog le.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin: 11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@ media screen and (max-width:772px){body{background:none;margin-top:0;max-width:n one;padding-right:0}}#logo{background:url(//www.google.com/images/errors/logo\_sm \_2.png) no-repeat}@media only screen and (min-resolution:192dpi){#logo{backgroun d:url(//www.google.com/images/errors/logo\_sm\_2\_hr.png) no-repeat 0% 0%/100% 100% ;-moz-border-image:url(//www.google.com/images/errors/logo\_sm\_2\_hr.png) 0}}@medi a only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www. google.com/images/errors/logo\_sm\_2\_hr.png) no-repeat;-webkit-background-size:100 % 100%}}#logo{display:inline-block;height:55px;width:150px} I/Corona ( 4457): \</style\> I/Corona ( 4457): \<a href=//www.google.com/\>\<span id=logo aria-label=Google\>\< /span\>\</a\> I/Corona ( 4457): \<p\>\<b\>400.\</b\> \<ins\>ThatÔÇÖs an error.\</ins\> I/Corona ( 4457): \<p\>Your client has issued a malformed or illegal request. \<ins\>ThatÔÇÖs all we know.\</ins\>