Event Tracking

This integration guide includes selected snippets from the SDK spec documentation. For more detail, always check the spec documentation of your specific SDK.

Any user action you track is called an Event. It is the core data that you send to your server.

An event consists of these parameters:

  • key - the name of the event (mandatory)
  • count - number of events (optional) (defaults to 1)
  • sum - sum/number to report with the event (optional)
  • dur - duration expressed in seconds (optional)
  • segmentation - an object with key/value pairs (optional)

To understand how you can leverage Events in your dashboard, check the guide below:

Web Android iOS Node Flutter Dart HarmonyOS React Native Windows Unity Java C++ GTM API Call

You can record an Event like this:

Asynchronous Synchronous
Countly.q.push(['add_event',{
  "key": "item purchase",
  "count": 1,
  "sum": 0,
  "dur": 0,
  "segmentation": {
    "item_name": "rolex"
  }
}]);
Map<String, Object> segmentation = new ConcurrentHashMap<>();
segmentation.put("item_name", "rolex");

Countly.sharedInstance().events().recordEvent("item purchase", segmentation, 1, 0, 0);
Objective-C Swift
NSDictionary* dict = @{@"item_name": @"rolex"};

[Countly.sharedInstance recordEvent:@"item purchase" segmentation:dict count:1 sum:0];
Countly.add_event({
  "key": "item purchase",
  "count": 1,
  "sum": 0,
  "dur": 0,
  "segmentation": {
    "item_name": "rolex"
  }
});
Map<String, Object>? segmentation = {
  'item_name': '7',
};

Countly.instance.events.recordEvent('item purchase', segmentation, 1, 0, 0);
final sdk = Countly.defaultInstance!;

await sdk.events.record(
  key: 'item purchase',
  count: 1,
  sum: 0,
  dur: 0,
  segmentation: {
    'item_name': 'rolex',
  },
);
const segmentation: Record<string, string> = { 'item_name': 'rolex' };

await Countly.sharedInstance().events.recordEvent('item purchase', segmentation, 1, 0, 0);
Countly.events.recordEvent("item purchase", { item_name: "rolex" }, 1, 0)
Segmentation segmentation = new Segmentation();
segmentation.Add("item_name", "rolex");

await Countly.RecordEvent("item purchase", 1, 0, 0, segmentation);
Dictionary<string, object> segmentation = new Dictionary<string, object>();
segmentation.Add("item_name", "rolex");

await Countly.Instance.Events.RecordEventAsync(key: "item purchase", segmentation: segmentation, count: 1, sum: 0, duration: 0);
HashMap<String, Object> segmentation = new HashMap<String, Object>();
segmentation.put("item_name", "rolex");

Countly.instance().events().recordEvent("item purchase", segmentation, 1, 0, 0);
std::map<std::string, std::string> segmentation;
segmentation["item_name"] = "rolex";

cly::Countly::getInstance().RecordEvent("item purchase", segmentation, 1, 0, 0);

002.png

curl --request POST \
--url 'https://YOUR_SERVER/i' \
--header 'Accept: application/json' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data 'app_key=APP_KEY' \
--data 'device_id=DEVICE_ID' \
--data 'timestamp=TIMESTAMP' \
--data 'hour=HOUR' \
--data 'dow=DAYOFTHEWEEK' \
--data 'tz=TIMEZONE'
--data 'events=[{"key":"EVENT_NAME","count":EVENT_COUNT,"sum":EVENT_SUM,"dur":EVENT_DUR,"segmentation":EVENT_SEGMENTATION}]'

You should expect the response to be:

# 200
{
  "result": "Success"
}

If you want to learn more about the feature integration and settings, have a look at the SDK documentation below:

Was this page helpful?
Reach out to us for any other questions.
Helpful?

Looking For More Help?