Giter Site home page Giter Site logo

gameanalytics-node-sdk's Introduction

Description

GameAnalytics Node SDK is a server-side wrapper for the GameAnalytics v2 REST API. This library offers full support for all of the event types outlined in the REST API documentation. It also covers the best practices specified including automatic batching of events, GZIP compression and validation of event data.

Installation

  • Install with npm: npm install gameanalytics-node-sdk
  • Install with Yarn: yarn add gameanalytics-node-sdk

Examples

First, create a free account at https://gameanalytics.com. Then, setup a game and get your key and secret to setup your SDK connection. In this example, we setup the SDK, start a new user session (must be the first thing you do) and track a design tutorial event (the events are just pseudocode).

const GameAnalytics = require('gameanalytics-node-sdk');

// Setup the SDK.
const GA = new GameAnalytics({
  key: 'GAME_KEY',
  secret: 'GAME_SECRET',
  build: '1.2.3',
  sandbox: false,
});

// Handle a player logging in.
game.on('login', (userId, client) => {
  GA.sessionStart(userId, {
    ua: client.ua,
    ip: client.ip,
    device: client.device,
    manufacturer: client.manufacturer,
    session_num: client.session_num,
  });
});

// Track a tutorial design event.
game.on('tutorial', (userId, step) => {
  GA.track('design', userId, {
    event_id: `Tutorial:${step}`,
  });
});

API

Constructor

new GameAnalytics({
  key: 'GAME_KEY', // Your GameAnalytics game key.
  secret: 'GAME_SECRET', // Your GameAnalytics game secret.
  build: '1.2.3', // The current build version of your game.
  sandbox: false, // Whether or not to use the sandbox for testing.
});

Methods

sessionStart(user, data)

Must be the first thing called to initialize the user session.

  • user: String The unique user ID that identifies this player.
  • data: Object The data to send with this event (minimum required are platform, os_version and sdk_version as found in the REST API docs for init).

sessionEnd(user)

Should be the last thing called for a user to identify the end of their game session. This will flush all pending events before this final event is sent.

  • user: String The unique user ID that identifies this player.

track(type, user, data)

Everything that happens between session start and end happens with this method to track any type of event.

  • type: String This can be a value of business, resource, progression, design or error.
  • user: String The unique user ID that identifies this player.
  • data: Object The data to send with this event. Check the REST API docs for each event type to see what is required for an event.

Properties

There are a list of default properties that can be sent with any event, which can be found in the REST API docs. Some of these properties are required; however, if they are passed with the sessionStart method, they will get automatically sent with each event during the player's session.

The platform and os_version can be identified automatically if you pass the ua property the User Agent string from the browser to sessionStart.

License

Copyright (c) 2018 James Simpson and GoldFire Studios, Inc.

Released under the MIT License.

gameanalytics-node-sdk's People

Contributors

goldfire avatar seiyria avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

gameanalytics-node-sdk's Issues

Browser support?

The readme states that this SDK is for Node projects. Is that a hard requirement or does it work for any javascript environment? I.e. for example in a browser or in React Native?

is it possible to batch requests?

For example, if I'm tracking a lot of stuff, I probably only want to flush the buffer once in a while, but would like to track it all normally in my code.

Some examples:

  • visiting a merchant and buying items multiple times,
  • killing a particular group of monsters,

I can probably think of others.

TypeError: Cannot read property 'start' of undefined

TypeError: Cannot read property 'start' of undefined
  File "/app/node_modules/gameanalytics-node-sdk/src/index.js", line 147, in _request.then
              start: this.users[user].start,
  File "internal/process/next_tick.js", line 68, in process._tickCallback

This happens to me sometimes, and I'm not sure why. It looks like there is no catch on sessionStart.

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.