RedMetrics2 (RM2) is a open-source open-data analytics service for online games and research.
This library helps send data from JavaScript applications (in the browser or on the desktop) to the online web service.
-
Install the library. Get it from NPM or clone and build this repository
-
Import or include the library.
Include dependency directly:
<script src="deps/rm2.bundle.js"></script>
Or import it:
import { WriteConnection } from "rm2";
- Create a connection object
const redmetricsConnection = new rm2.WriteConnection({
protocol: , // "http" or "https"
host: , // host of the service
port: , // optional
apiKey: , // API key that corresponds to the game
session: , // optional: information about the player session you would like recorded. Can be updated later
});
- Connect (async)
redmetricsConnection
.connect()
.then(function () {
console.log("Connected to RM2");
})
.catch(function () {
console.error("Problem connecting");
});
- Send events
redmetricsConnection.postEvent({
type: , // event name
customData: { }, // optional
});
- Optionally, update the session in progress
redmetricsConnection.updateSession({
externalId: ,
customData: ,
});
To upgrade from RM1, do the following:
- Include or import the new file (
rm2.bundle.js
) - Update the connection information to include API key instead of the "game version"
redmetrics.prepareWriteConnection()
becomesnew rm2.WriteConnection()
- Change references from
player
tosession
playerId
=>sessionId
updatePlayer()
=>updateSession()
Install dependencies with npm install
.
Copy template.env
to tests/.env
and fill in the environmental variables such as API_KEY
.
Run tests with npm run test
.
Build for multiple formats with npm run bundle
or npm run watch
.