Giter Club home page Giter Club logo

godot-gameanalytics's Introduction

Godot-GameAnalytics

Apr 23, 2018 - Cristiano Reis Monteiro [email protected]

Native GDScript for GameAnalytics in Godot

When I first started learning Godot I notice the limitation when it comes to capture game analytics. The vast majority of options are incomplete in the sense that supports only one platform, missing functions etc, besides the regular need to recompile the engine, rebuild export templates, etc.

In search of a native, cross platform solution, identified that https://gameanalytics.com/ had a REST API sample in Python

Worked to convert it to GDScript (hardest part was implementing HMAC-SHA256).

The result is here.

Yes, the code is crude, poluted, redundant, etc, but it works. Don't complain, go fix it and share the result.

PLEASE NOTE: This GDScript makes use of https://github.com/xsellier/godot-uuid, so, download uuid.gd and place in the same folder as GameAnalytics.gd

USAGE INSTRUCTIONS:

. Add GameAnalytics.gd and uuid.gd to your root resources folder

. Add that to your main .gd:

var GAs = load("res://GameAnalytics.gd")
var GA = GAs.new()

func _ready():
  GA.game_key = <your_game_key_supplied_by_GameAnalytics>
  GA.secret_key = <your_secret_key_supplied_by_GameAnalytics>
  GA.base_url = "http://api.gameanalytics.com"

  # Run once per session
  init_response = GA.request_init()

  # Add events to queue
  GA.add_to_event_queue(GA.get_test_design_event("player:new_level", 1))
  GA.add_to_event_queue(GA.get_test_design_event("player:new_level", 2))

  # Submit events and flush queue - return code will indicate success (200) or failure (400, 401, 404)
  var returned = GA.submit_events()

The following GameAnalytics calls are also available:

add_to_event_queue(get_test_design_event(<string>, <value>))
add_to_event_queue(get_test_user_event())
add_to_event_queue(get_test_business_event_dict())
add_to_event_queue(get_test_session_end_event(200))

Study GameAnalytics.gd (commented examples there) and GameAnalytics REST API page to understand what else can be submitted.

NOTE: While testing on my Windows machine, GameAnalytics refused "Windows" as a valid os/platform, so I put this code before GA.request_init() to work around that. YMMV

	if GA.platform == "Windows":
		GA.platform = "android"

	if GA.os_version == "Windows":
		GA.os_version = "android 4.4.4"

TODO

. Correctly calculate client_ts offset

. Enable GZip compression (partially done / commented out)

. Better error treatment

. Fix comments and clean up code

godot-gameanalytics's People

Contributors

montecri avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.