GameAnalytics / GA-SDK-DEFOLD

Repository for GameAnalytics Defold SDK
MIT License
14 stars 7 forks source link

ReferenceError: gameanalytics is not defined | on HTML5 #12

Closed Jerakin closed 5 years ago

Jerakin commented 5 years ago

If HMTML 5 isn't supported it would still be awesome if there was a mock implementation that threw the calls away, right now the game crashes.

the1schwartz commented 5 years ago

It looks like you might need to add this line to your html5 template file: <script type='text/javascript' src="GameAnalytics.js"></script>

After you have done that it should fix the error you are getting, or else let me know if you are still getting the error.

subsoap commented 5 years ago

@Jerakin Make sure you wrap your native extension calls in code such as

if gameanalytics then
  ...
end
Jerakin commented 5 years ago

@subsoap That's a good point, unfortunately I haven't separated the gameanalytics call to a different module so now they are kinda all over my code.

I ended up doing

local system = sys.get_sys_info().system_name
if system == "HTML5" then
    gameanalytics = require "utils.mock_gameanalytics"
end

The module only have empty functions. Is this solution fine you think?

Maybe it would be better as if not gameanalytics then 🤔

subsoap commented 5 years ago

@Jerakin If it doesn't break then that is good at least, but you should probably refactor eventually too.

Jerakin commented 5 years ago

@the1schwartz After adding it I get this in the console. It doesn't send the tracking.

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://api.gameanalytics.com/v2/dba33986f167a0297a66e16ffa86787d/events. (Reason: CORS request did not succeed).[Learn More]
Warning/GameAnalytics: Event queue: Failed to send events to collector - Retrying next time GameAnalytics.js:2:8218
subsoap commented 5 years ago

Try testing on an actual server and not localhost?

Jerakin commented 5 years ago

I am not sure what you mean. The app is running from itch.io I see that I have gotten some data sent. 5 users while the itch analytics shows maybe ~15

subsoap commented 5 years ago

Maybe a CORS header is missing on the HTML page of your game and your browser is strict about it while other browsers are not?

Jerakin commented 5 years ago

Yeah maybe. I have tried setting it but with no luck (granted my knowledge of html is limited). I read that somewhere that this should be set on the server however. GameAnalytics is calling https://rubick.gameanalytics.com/v2 and https://api.gameanalytics.com/v2/ so maybe it is something on their end? Will create a new ticket for it as it isn't related to this (to increase visibility if nothing else)

subsoap commented 5 years ago

@the1schwartz what do you think?

the1schwartz commented 5 years ago

Our backend team has recently made some changes that potentially could give some problems but we didn't experience them ourselves during our testing but I have asked them now if they think the changes could cause this.