Implementation

Using the powerful networking functions in GameSalad® and the intelligent back-end system from APPFormative™, you are able to have complete control over the events that you would like to track, as well as control the functionality of your app. At all times, the privacy of your users is respected, as no personal identifiable information is transmitted.



The Basics - for GameSalad®

Estimated time to implement: ~4 minutes.


Step 1.

Register for the free account here on APPFormative™, then go to the "MY APPS" menu selection. Here you will define your App. Once saved, you will be presented with a unique APPID for your App. Clicking on the "copy" symbol allows you to save the ID to the clipboard for later retrieval.





Step 2.

In GameSalad we do not need to compile a 3rd party library into our App to accomodate Analytics.

Simply start with your desired project in the GameSalad Creator, or start a new one.

On the Project Info screen, make sure to select "My Own Server" from the Multiplayer droplist. This will activate the networking features of GameSalad.

First we will create a Table called "T_Analytics", with one row and ten columns. Define the type of the columns as "Text".

Now double click on the column header and enter or paste the APPID, which you created in Step 1, as indicated in the image below.





Step 3.

Go to the first scene of your project and select the Attributes tab. We are going to add four game level Attributes and assign them values as follows:

- send_setup_URL of type text with the value https://www.appformative.com/gs/send_setup.mox

- send_event_URL of type text with the value https://www.appformative.com/gs/send_event.mox

- get_setup_URL of type text with the value https://www.appformative.com/gs/get_setup.mox?ID=0000-0000-0000-0000 (the digits represent your APPID from above)

- AF_UserID of type text





Step 4.

Next we create an actor, preferably call it AF_Start, as this actor should only be run once at the start of your app.

We start off by adding the following self attributes:

- firstcontact of type integer

- secondcontact of type integer





Step 5.

Now drag a Timer Behaviour into the actor with "After 0.02 seconds" and "Run to Completion" properties.

Always place network code in a Timer. Timers spawn and run as seperate events, in parallel to the rest of your code. This will insure that the network functions can complete unhindered and do not jam your normal code.

Into this Timer we will place a Change Attribute behavior, to set the game.AF_UserID Attribute to a 4 digit random number. To do this, call up the random() function in the expression editor, and give it a range from 1111 to 9999.

Next, drag a "Change Table Value" Behavior into the Timer, selecting our game level attribute game.T_Analytics in the Table field, setting Row equal to 1. In the Columns section, set Column to 1 and enter game.AF_UserID as the value, using the expression editor. Press the "+" sign next to the entry to create a second column entry. Enter 2 for the Column, and insert game.Clock.Hour into the Value field by selecting Devices -> Clock -> Hour from the expression editor.

Now we are going to drag a "Network Send Table To URL" Behavior into the Timer. Pick the appropriate Attributes and Table as indicated in the image below.





Step 6.

Next we are going to drag a Rule (A) into the Timer with the condition if Attribute self.firstcontact = 1. This will trigger the contents of the Rule immediately after the Callback Attribute from the "Network Send Table To URL" Behaviour gives us a success signal.

We now drag a "Network Get Table From URL" Behaviour into this Rule and fill it with the appropriate Attributes and Table, as seen below.





Step 7.

For the final step, we will create another Rule (B) inside the Timer, now with the condition if Attribute game.secondcontact = 1. This will trigger the contents of the Rule immediately after the Callback Attribute from the "Network Get Table From URL" Behaviour gives us a success signal.

Into this Rule we will place a Change Attribute behavior, to set the game.AF_UserID Attribute to the tableCellValue with the parameters game.T_Analytics,1,1, using the expression editor to enter these values.

Lastly, we will add a "Save Table" Behaviour, remembering to select the appropriate Table.





Congratulations!

Your project is now ready to gather analytics and record custom events. In fact, when run, it will already be sending a data point every time your App is started.