npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gamedock-web-tracker

v4.3.0

Published

Gamedock web tracker

Downloads

25

Readme

Gamedock Web Tracker

Gamedock Web Tracker is a basic helper to send events to the Gamedock Backend.

Project install and build

  • $ npm install
  • $ npm run build

Project publish

It is necessary to have an OOSS token in order to publish. In order to set it up, you need to copy the config-template.js file to a config.js file in the same folder and place your token into the TOKEN variable.

  • commit your changes
  • $ npm version [major | minor | patch]
  • $ npm publish

Documentation

Installation

You can either install and build the project yourself, in that case you will find the files inside the dist\script and dist\umd directories, or you can use one of our CDN links:

  • https://cdn.gamedock.io/gamedock-web-tracker/4.3.0/umd/gamedock-sdk.js
  • https://cdn.gamedock.io/gamedock-web-tracker/4.3.0/umd/gamedock-sdk.min.js
  • https://cdn.gamedock.io/gamedock-web-tracker/4.3.0/script/gamedock-sdk.min.js
  • https://cdn.gamedock.io/gamedock-web-tracker/4.3.0/script/gamedock-sdk.js

We have two versions of the Gamedock Web Tracker, one that can be included explicitly as a script located at dist/script/gamedock-sdk.js, and an UMD one that can be included both as a script or an AMD which is located at dist/amd/gamedock-sdk.js. Both files have their minified versions dist/script/gamedock-sdk.js and dist/umd/gamedock-sdk.js respectively.

If you want the Tracker to be defined on the global scope, or you are injecting the Tracker into pages of unknown content using document.write or similar methods, we suggest that you use the normal script to avoid collision with other potentially existing AMD loaders.

<script src="https://some-cdn.com/gamedock-sdk.js"></script>

If you already use and AMD loader such as require.js in your page we suggest you use the UMD version.

require('gamedock-sdk',function(GamedockSDK) {})

Initialization

First thing to do before sending any events is to initialize the SDK via the initialize function. This function returns an GamedockSDK object that you can later use to send events. Additional calls to the initialize function with the same arguments will return the same instance instead of creating a new one.

The initialize function has two required arguments organizationId and domainId, and an optional environment which is only for debugging purposes.

The organizationId is the id of the organization that the domain belongs to.

The domainId is the id of the domain that the tracking is taking place.

The environment is the environment that events will be sent to, can be either STG or PRD. - This is only for debugging purposes.

Example:

var gdSDK = GamedockSDK.initialize('amazing_org',43);

Sending Events

The GamedockSDK object has a Tracking object which is responsible for sending the events to the Backend. It has only one method, the trackEvent method.

The trackEvent method takes two arguments, the eventName and eventData, which are the Event name String and Event data object respectively. The event names and data vary and are not part of this documentation, but there are some events that are quite common such as the pageview and gameplay which we'll give an example bellow. You can find the full documentation of the events that are available to your backend by visiting the link: https://tracker.gamedock.io/v1/events-tracker/track_config/ followed by your target id. e.g. if you target id would be amazing_org your documentation link would be:

https://tracker.gamedock.io/v1/events-tracker/track_config/amazing_org

Alternatively, you can access the documentation by invoking the documentation function in an instance of the tracker the console. e.g:

var gdSDK = GamedockSDK.initialize('amazing_org',43);
gdSDK.documentation();

This will open the documentation page in a new tab. Of course, if the tracker is already initialized you don't have to do it again.

Sending a pageView event

The PageView requires the following arguments:

  • pageId the id of the page the tracking is taking place this should be the gameId if it is a game page.
  • pageType the type of the page the tracking is taking place e.g. homepage, gamepage
  • isAuthorized a boolean value that describes if the user is logged in, it should be omitted if the website doesn't have a login feature

example:

var gdSDK = GamedockSDK.initialize('amazing_org',43);
gdSDK.tracking.trackEvent('pageview',{ pageId:'amazing-page', pageType:'even-more-amazing-category', isAuthorized:true});
gdSDK.tracking.trackEvent('gameplay',{ pageId:'amazing-page', pageType:'even-more-amazing-category', isAuthorized:true});

if you have a single event it is also fine if you inline it:

GamedockSDK.initialize('amazing_org',43).tracking.trackEvent('pageview',{ pageId:'amazing-page', pageType:'even-more-amazing-category', isAuthorized:true});

as mentioned before, additional calls to the initialize method with the same arguments will just return the same object.

The trackEvent method returns a promise which will be resolved with a ResponseEvent object if succeeded or an Error if failed. On a failed event due to wrong arguments, a detailed log of what went wrong will be logged in the console.

Creating your own wrapper

The tracking feature is very basic and as low level as possible but it is very easy to create a thin wrapper on top of it to fit your needs.

Example wrapper

var gdSDK = (function(gdSDK){
    return {
            trackPageView:function(pageId,pageType,isAuthorized) {
                return gdSDK.tracking.trackEvent('pageview',{pageId:pageId.toString(),pageType:pageType.toString(),isAuthorized:!!isAuthorized})
            }, 
            trackGamePlay:function(pageId,pageType,isAuthorized) {
                return gdSDK.tracking.trackEvent('gameplay',{pageId:pageId.toString(),pageType:pageType.toString(),isAuthorized:!!isAuthorized})
            } 
           }
 })(GamedockSDK.initialize('amazing_org',43))