Setup
InApp templates offer most of the functions of FollowAnalytics through a Javascript interface. For example, it is possible to expand the tagging plan for user actions that happen inside the InApp message.
These functions are available through the FollowAnalytics
object. In order to use this object, it is recommended to add the file fa-sdk.js
inside the root folder of your template and link it from your html
files.
After adding the link, you can use the FollowAnalytics
object from the Javascript code of the template.
Example:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="fa-sdk.js"></script>
<script type="text/javascript">
// Now we have access to the FollowAnalytics object
FollowAnalytics.logEvent('MyTemplateHasBeenDisplayed');
</script>
</head>
<body>
</body>
</html>
You can download a mock implementation of the FollowAnalytics
object here. Put a copy of this file in the root folder of the template. Remember that this is only a mock implementation, useful for offline development outside the context of the mobile application. In the mock implementation, all methods are forwarded to the browser's console. This way, we can verify that the correct methods are called during the development of the template.
Before the template is displayed inside the mobile application, this file is replaced by the actual implementation which will provide a bridge between Javascript and the native runtime of the SDK. Therefore, you shouldn't modify this file in any way; your modifications will be lost.
Method Reference
Current campaign
FollowAnalytics.CurrentCampaign.close()
Closes the current campaign. Useful in order to implement custom close buttons.
FollowAnalytics.CurrentCampaign.logAction(action_name)
Logs a special custom tag that is linked with the current campaign. These tags are collected by the server and the stats are visible inside the result page of the campaign.
action_name
: A non-empty string with the name of the action to log.
The SDK bridge
Most of the standard functions of the SDK are available through the Javascript bridge. Here is a complete reference.
FollowAnalytics.getUserId()
Returns the current user id.
FollowAnalytics.getDeviceId()
Returns the current device id.
FollowAnalytics.getSDKVersion()
Returns the SDK version.
FollowAnalytics.getSDKPlatform()
Returns the SDK platform (Android, iOS or Web).
FollowAnalytics.logEvent(name, details)
Logs a custom event of the tagging plan.
-
name
: A non-empty string for the custom event's name. -
details
: The details of the event. There are 3 different accepted typesundefined
eg.
FollowAnalytics.logEvent('HomePage')
string
eg.
FollowAnalytics.logEvent('ScreenDisplayed', 'HomePage');
object
eg.
FollowAnalytics.logEvent('ProcuctAddedToCart', { product_id: 123, color: 'red'});
-
FollowAnalytics. logError(name, details)
Logs a custom error of the tagging plan.
-
name
: A non-empty string for the custom error's name. -
details
: The details of the error. There are 3 different accepted typesundefined
eg.
FollowAnalytics.logError('SomeError')
string
eg.
FollowAnalytics.logError('ErrorInPage', 'HomePage');
object
eg.
FollowAnalytics.logError('ErrorInProduct', { product_id: 123, color: 'red'});
User attributes
FollowAnalytics.UserAttributes.setFirstName(firstName)
-
firstName
: a string ornull
. -
FollowAnalytics.UserAttributes.setLastName(lastName)
-
lastName
: a string ornull
. -
FollowAnalytics.UserAttributes.setEmail(email)
-
email
: a string ornull
. -
FollowAnalytics.UserAttributes.setDateOfBirth(dateOfBirth)
-
dateOfBirth
: a Javascript date object or null. Warning: In Javascript, the month is 0-based. For examplenew Date(2000, 1, 1)
corresponds to 1 February 2000. -
FollowAnalytics.UserAttributes.setGender(gender)
-
gender
: One of the valuesFollowAnalytics.Gender.MALE
,FollowAnalytics.Gender.FEMALE
,FollowAnalytics.Gender.OTHER
ornull
. -
FollowAnalytics.UserAttributes.setCountry(country)
-
country
: 2-letter ISO code string of the country. -
FollowAnalytics.UserAttributes.setCity(city)
-
city
: a string ornull
. -
FollowAnalytics.UserAttributes.setRegion(region)
-
region
: a string ornull
. -
FollowAnalytics.UserAttributes.setProfilePictureUrl(profilePictureUrl)
-
profilePictureUrl
: a URL string ornull
. -
FollowAnalytics.UserAttributes.setString(key, value)
key
: a string, the attribute's name.-
value
: a string ornull
. -
FollowAnalytics.UserAttributes.setNumber(key, value)
key
: a string, the attribute's name.-
value
: a Javascript number (integer or decimal) ornull
. Avoid special numbers likeNaN
orInfinity
. -
FollowAnalytics.UserAttributes.setBoolean(key, value)
key
: a string, the attribute's name.-
value
: a boolean (true
orfalse
) ornull
. -
FollowAnalytics.UserAttributes.setDate(key, value)
key
: a string, the attribute's name.-
dateOfBirth
: a Javascript date object or null. Warning: In Javascript, the month is 0-based. For examplenew Date(2000, 1, 1)
corresponds to 1 February 2000. -
FollowAnalytics.UserAttributes.setDateTime(key, value)
key
: a string, the attribute's name.-
dateOfBirth
: a Javascript date object or null. Warning: In Javascript, the month is 0-based. For examplenew Date(2000, 1, 1)
corresponds to 1 February 2000. -
FollowAnalytics.UserAttributes.clear(key)
Clears the attribute. This is equivalent to setting the attribute to null
.
-
key
: a string, the attribute's name. -
FollowAnalytics.UserAttributes.addToSet(key, ...values)
Adds one or more elements to a set.
key
: a string, the attribute's name.-
values
: one or more strings. Eg:FollowAnalytics.UserAttributes.addToSet('my_set', 'one', 'two', 'three')
-
FollowAnalytics.UserAttributes.removeFromSet(key ...values)
Removes one or more elements to a set.
key
: a string, the attribute's name.-
values
: one or more strings. Eg:FollowAnalytics.UserAttributes.removeFromSet('my_set', 'one', 'two', 'three')
-
FollowAnalytics.UserAttributes.clearSet(key)
Removes all the elements from a set
key
: a string, the attribute's name.