gamedock-web-tracker
v4.3.0
Published
Gamedock web tracker
Downloads
8
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, gamepageisAuthorized
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))