Actionable Analytics

ShepHertz has added Event API to its broad gamut of services for IoT, which is a powerful analytics API and allows the developer to track app events as well as real time sessions of all the connected devices.

App42 provides powerful management console to track and analyse these events in just few clicks. It also provides option to drill down your data based on custom properties which one can send along with the event name.

Not setup your Raspberry Pi yet? Click here to follow the step-by-step guide

Import

#include "App42API.h"

Initialize

Build Service

EventService *eventService = App42API::BuildEventService();

Track Event:

At occurrence of an event (For example, a temperature monitoring system can log temperature when it goes beyond threshold), one can log events using trackEvent method available in Event Service as shown below.

Required Parameters

eventName - Name of event. properties- Properties which you want to add along with user event
App42API::Initialize("API_KEY", "SECRET_KEY");  
EventService *eventService = App42API::BuildEventService();
SampleClass *sampleClassInstance = new SampleClass();
App42API::setLoggedInUser(“Nick”);
App42Object *app42Object = new App42Object();
app42Object->setObject(“DeviceType”,”Temperature Monitor”); 
eventService->TrackEvent(“Your_Event_Name”, app42Object,app42callback(SampleClass::onEventRequestCompleted, sampleClassInstance));

void SampleClass::onEventRequestCompleted( void *response)
{
    App42Response *app42Response = (App42Response*)response;
    printf("\ncode=%d...=%d",app42Response->getCode(),app42Response->isSuccess);
    printf("\nResponse Body=%s",app42Response->getBody().c_str());
     
    if (app42Response->isSuccess)
    {
        printf("\nSUCCESS”);
    }
    else
    {
        printf("\nerrordetails:%s",app42Response->errorDetails.c_str());
        printf("\nerrorMessage:%s",app42Response->errorMessage.c_str());
        printf("\nappErrorCode:%d",app42Response->appErrorCode);
        printf("\nhttpErrorCode:%d",app42Response->httpErrorCode); 
    }
}

Set Logged in User Properties

If you want to set user property that you want to track with your app events, use the following statement to set it.

Required Parameters

properties- Properties which you want to add along with user event
App42API::Initialize("API_KEY", "SECRET_KEY");  
EventService *eventService = App42API::BuildEventService();
SampleClass *sampleClassInstance = new SampleClass();
App42API::setLoggedInUser(“Raspberry Pi”);
App42Object *app42Object = new App42Object();
app42Object->setObject(“DeviceType”,”Temperature Monitor”);
eventService->SetLoggedInUserProperties(“Your_Event_Name”, app42Object,app42callback(SampleClass::onEventRequestCompleted, sampleClassInstance));

void SampleClass::onEventRequestCompleted( void *response)
{
    App42Response *app42Response = (App42Response*)response;
    printf("\ncode=%d...=%d",app42Response->getCode(),app42Response->isSuccess);
    printf("\nResponse Body=%s",app42Response->getBody().c_str());
        
    if (app42Response->isSuccess)
    {
        printf("\nSUCCESS”);
    }
    else
    {
        printf("\nerrordetails:%s",app42Response->errorDetails.c_str());
        printf("\nerrorMessage:%s",app42Response->errorMessage.c_str());
        printf("\nappErrorCode:%d",app42Response->appErrorCode);
        printf("\nhttpErrorCode:%d",app42Response->httpErrorCode); 
    }
}

Update Logged in User Properties

You can update logged in user properties using following snippet.

Required Parameters

properties- Properties which you want to add along with user event
App42API::Initialize("API_KEY", "SECRET_KEY");  
EventService *eventService = App42API::BuildEventService();
SampleClass *sampleClassInstance = new SampleClass();
App42API::setLoggedInUser(“Raspberry Pi”);
App42Object *app42Object = new App42Object();
app42Object->setObject(“DeviceType”,”Temperature Monitor”);
eventService->SetLoggedInUserProperties(“Your_Event_Name”, app42Object,app42callback(SampleClass::onEventRequestCompleted, sampleClassInstance));

void SampleClass::onEventRequestCompleted( void *response)
{
    App42Response *app42Response = (App42Response*)response;
    printf("\ncode=%d...=%d",app42Response->getCode(),app42Response->isSuccess);
    printf("\nResponse Body=%s",app42Response->getBody().c_str());   
    
    if (app42Response->isSuccess)
    {
        printf("\nSUCCESS”);
    }
    else
    {
        printf("\nerrordetails:%s",app42Response->errorDetails.c_str());
        printf("\nerrorMessage:%s",app42Response->errorMessage.c_str());
        printf("\nappErrorCode:%d",app42Response->appErrorCode);
        printf("\nhttpErrorCode:%d",app42Response->httpErrorCode); 
    }
}