JavaScript SDK

Integrating your game with INFINARIO is the first step in getting closer to your players. After a quick integration, you will immediately see actions that players do in your game. If you need any assistance in deciding which API is the best for your game, please contact our integration specialist.

When should I integrate through JavaScript?

Integration through JavaScript is recommended for web browser games or for games coded in other languages that still make use of JavaScript.


Basic integration

To integrate with INFINARIO using JavaScript, you need to copy-paste the following initialization code into the header of the webpage your game is running in. This step is an essential prerequisite for identifying your players and tracking their actions.


This will initialize INFINARIO with your project token (your unique project identifier) so that every action will be tracked into your project correctly. You can find your project token inside the Project overview by clicking Overview in the left menu. This code must be included in every page where you want to track actions of your players.

How do I know that I initialized INFINARIO correctly?

After copy-pasting the initialization code, open your web game in a new window. This single page visit should be enough to identify whether your basic integration is working. Check if you integrated successfully by clicking the integration button on the top of the integrate live data page and wait for the result. Contact our JavaScript integration specialist.  


 

Tracking your first event

Players in your game do different actions. These actions are called events and by tracking them you gain insights vital for developing the perfect game. To track your first event, you need to copy-paste the following code into an appropriate place in your game.

This will track the event named quest with the three attributes of name, status and playerLevel to currently identified player. For example, the attribute status has the value completed.

Of course your event doesn’t have to be named quest and it doesn’t have to have this set of attributes. Other useful examples of events would be registration or purchase. You can also get creative and make your own events with custom attributes – only you decide what to track about your players. However, remember that in game analytics, less is more and you want to start with a few basic events only.

Tip: We recommend you to avoid using internal IDs or numbers as values for attributes. A quest status completed is much more comprehensible than a quest status 3.

You can delete events you tracked at any time easily.


Identifying your players

To know your players better, you need to identify them with a unique identifier, such as e-mail or username. Copy-paste the following snippet into the code where it is possible to identify the player for the first time (for example right after login or registration) so that every event the player creates from this point on will be tracked correctly and directly to him.

This will identify the player with a username gordon.freeman@blackmesa.com. Without identification, events are added to anonymous players. Please note that you don’t lose any information about these events after you identify the player – these events will be transferred to a newly identified player.   Tip: We recommend you to use the email address as an identifier for known players.  


 

Updating the player’s profile

In addition to tracked events, every player in INFINARIO has a set of attributes. Attributes can be used to contact the player using a campaign, or to specify the player in your game more accurately. Copy-paste the following snippet into the code where you want to update player attributes.

This will update the player attributes player_level, registration_date and email.

If a player property doesn’t exist at the time the code is executed, the property will be created. You can create properties as you need them without worrying about their management. If you don’t need them anymore, you can delete them easily.

Please note that if you choose to identify your player with an email, you still need to specify the player attribute email. This is needed because of the distinction between identification attributes and the player email.


This guide should have provided you with all the basics needed to start tracking your first events. We would love to help you get started as soon as possible, so if you have any questions, please contact our integration specialist.

Advanced tracking

Customizing default tracking

Default tracking behaviour can be adjusted in the infinario.initialize(options) call:

You can also specify custom properties to be emitted with the customer_login and customer_logout events.

Content modifying

It is also possible to enable content modifying by adding this code into the initialization:

modify: {
            enabled: true, // enables content modifying
            overlay: false, // enables/disables overlay (can be ommitted so the default = false is used)
            delay: 500 // sets the delay for how long the overlay will be displayed (only if overlay is enabled, defaults to 500 if omitted)
        }

Example:

<script type="text/javascript">
    infinario.initialize({
        token: 'PROJECT TOKEN',
        modify: {
            enabled: true, 
            overlay: false, 
            delay: 500
        }
    });
</script>

Action tracking

You can emit custom events when clicking links:

HTML campaigns

To display the content of your HTML campaign for the current user, use the following code:

If you want to work with HTML yourself, use the getHtml method instead:

Limitations

Characters . and $ are not allowed to be used in JSON keys. However, they can be used as values.