Gamedock web tracker
npm install gamedock-web-trackerGamedock Web Tracker is a basic helper to send events to the Gamedock Backend.
config-template.js file to a config.js file in the same folder and place your token into the TOKEN variable.#### 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:
[start-cdns]: #
* 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
[end-cdns]: #
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.
``html`require.js
If you already use and AMD loader such as in your page we suggest you use the UMD version.`javascript`
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:
`javascript`
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.amazing_org
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 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:`Javascript`
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:
`javascript`
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:javascript`
GamedockSDK.initialize('amazing_org',43).tracking.trackEvent('pageview',{ pageId:'amazing-page', pageType:'even-more-amazing-category', isAuthorized:true});initialize
as mentioned before, additional calls to the 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.
javascript
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))
``