MetricManagerIncrementTodayCAPI.c

A simple example of a metric that doesn't worry about updating history, and just increments a single value in response to an action. This is for apps that do not already have a way of knowing the current value.

#include <libusermetricsinput/usermetricsinput.h>
int main(int argc, char *argv[]) {
// We start with a manager object
UserMetricsInputMetricManager metricManager =
usermetricsinput_metricmanager_new();
// Create a parameters object
UserMetricsInputMetricParameters parameters =
usermetricsinput_metricparameters_new("photo-app-photos");
// Set its attributes
usermetricsinput_metricparameters_set_format_string(parameters,
"<b>%1</b> photos taken today");
usermetricsinput_metricparameters_set_empty_data_string(parameters,
"No photos today");
usermetricsinput_metricparameters_set_text_domain(parameters, APP_ID);
// You can hold onto this shared object for as long as you want
UserMetricsInputMetric metric = usermetricsinput_metricmanager_add(
metricManager, parameters);
// Remember to free the parameters object after use
usermetricsinput_metricparameters_delete(parameters);
// Providing a blank username string will use the current
// user according to the USER environment variable.
usermetricsinput_metric_increment(metric, 1, "");
// Now we're done with the manager
usermetricsinput_metricmanager_delete(metricManager);
return 0;
}
usermetricsinput.h
usermetricsinput_metricparameters_set_format_string
USERMETRICSINPUT_EXPORT void usermetricsinput_metricparameters_set_format_string(UserMetricsInputMetricParameters metricParameter, const char *formatString)
Set the string to print in the output API, e.g. "<b>%1</b> messages received today".
usermetricsinput_metricmanager_add
USERMETRICSINPUT_EXPORT UserMetricsInputMetric usermetricsinput_metricmanager_add(UserMetricsInputMetricManager metricManager, UserMetricsInputMetricParameters metricParameters)
Register a new UserMetricsInputMetric.
usermetricsinput_metricparameters_delete
USERMETRICSINPUT_EXPORT void usermetricsinput_metricparameters_delete(UserMetricsInputMetricParameters metricParameters)
Free a UserMetricsInputMetricParameters.
UserMetricsInputMetric
void * UserMetricsInputMetric
A single user metric, e.g. "number of e-mails today" or "photos taken today".
Definition usermetricsinput.h:57
UserMetricsInputMetricParameters
void * UserMetricsInputMetricParameters
Parameters for constructing a metric.
Definition usermetricsinput.h:52
usermetricsinput_metric_increment
USERMETRICSINPUT_EXPORT void usermetricsinput_metric_increment(UserMetricsInputMetric metric, double amount, const char *username)
Increment the "today" value for a simple user metric.
usermetricsinput_metricmanager_delete
USERMETRICSINPUT_EXPORT void usermetricsinput_metricmanager_delete(UserMetricsInputMetricManager metricManager)
Free a UserMetricsInputMetricManager.
UserMetricsInputMetricManager
void * UserMetricsInputMetricManager
A central place for registering user metrics.
Definition usermetricsinput.h:47
usermetricsinput_metricparameters_set_text_domain
USERMETRICSINPUT_EXPORT void usermetricsinput_metricparameters_set_text_domain(UserMetricsInputMetricParameters metricParameter, const char *textDomain)
Set the translation domain.
usermetricsinput_metricparameters_set_empty_data_string
USERMETRICSINPUT_EXPORT void usermetricsinput_metricparameters_set_empty_data_string(UserMetricsInputMetricParameters metricParameter, const char *emptyDataString)
set the string to print in the case of no data, e.g. "No messages received today"
usermetricsinput_metricparameters_new
USERMETRICSINPUT_EXPORT UserMetricsInputMetricParameters usermetricsinput_metricparameters_new(const char *dataSourceId)
Construct a new UserMetricsInputMetricParameters.
usermetricsinput_metricmanager_new
USERMETRICSINPUT_EXPORT UserMetricsInputMetricManager usermetricsinput_metricmanager_new()
Construct a new UserMetricsInputMetricManager.