analytics.init()

Type Function
Library [analytics.*][api.library.analytics]
Return value none
Revision Release 2024.3703
Keywords analytics, Flurry
See also analytics.logEvent()

Overview

Initializes the Flurry analytics library. Once initialized, use analytics.logEvent() to log events.

Syntax

analytics.init( apiKey )
apiKey (required)

String. The API key provided by Flurry — see the next section for details.

API Key

To get the apiKey value, register for an account with Flurry. Once you've logged into the Flurry dashboard, go to Manage Applications. From there, click Create a new app, then choose iPhone, iPad, or Android as appropriate. This will create the application key.

Gotchas

Android

On Android, you must set the INTERNET permission within the build.settings file to record and send analytics data.

You may optionally set the ACCESS_FINE_LOCATION and ACCESS_COARSE_LOCATION permissions if you want Flurry to record the end user's current location such as latitude and longitude. If you do not set these location permissions, Flurry can only record the country that the app was used in, based on the device's locale and region settings. Note that if you add these location permissions, you should not require device features like GPS, as doing so may prevent downloading of the app on a device without these features.

settings =
{
    android =
    {
        usesPermissions =
        {
            "android.permission.INTERNET",
            -- The following permissions are optional.
            -- If set, Flurry will also record current location via GPS and/or WiFi.
            -- If not set, Flurry can only record which country the app was used in.
            "android.permission.ACCESS_FINE_LOCATION",    --fetches location via GPS
            "android.permission.ACCESS_COARSE_LOCATION",  --fetches location via WiFi or cellular service
        },
        usesFeatures =
        {
            -- If you set permissions "ACCESS_FINE_LOCATION" and "ACCESS_COARSE_LOCATION" above,
            -- you should set the app to NOT require location services:
            { name="android.hardware.location", required=false },
            { name="android.hardware.location.gps", required=false },
            { name="android.hardware.location.network", required=false },
        },
    },
}

Example

local analytics = require( "analytics" )

-- initialize with proper API key corresponding to your application
analytics.init( "API_KEY" )

-- log events
analytics.logEvent( "Event" )