// social void sendSocial(QString socialNetwork, QString socialAction, QString socialActionTarget) const { QUrl params = build_metric("social"); params.addQueryItem("sn", socialNetwork); params.addQueryItem("sa", socialAction); params.addQueryItem("st", socialActionTarget); send_metric(params); }
static int handle_request(struct mg_connection *conn) { static const char *PONG_STR = "{\"version\" : \"brubeck %s\", \"pid\" : %d, \"status\" : \"%s\"}\n"; if (!strcmp(conn->request_method, "GET")) { if (!strcmp(conn->uri, "/ping")) { struct brubeck_server *brubeck = conn->server_param; const char *status = "OK"; if (brubeck->at_capacity) status = "CAPACITY"; if (!brubeck->running) status = "SHUTDOWN"; send_headers(conn); mg_printf_data(conn, PONG_STR, GIT_SHA, getpid(), status); return MG_TRUE; } if (!strcmp(conn->uri, "/stats")) return send_stats(conn); if (starts_with(conn->uri, "/metric/")) return send_metric(conn); } if (!strcmp(conn->request_method, "POST")) { if (starts_with(conn->uri, "/expire/")) return expire_metric(conn); } return MG_FALSE; }
// appview void sendAppview(QString appName, QString appVersion = "", QString screenName = "") const { QUrl params = build_metric("appview"); if (_appName.size()) params.addQueryItem("an", _appName); else if (appName.size()) params.addQueryItem("an", appName); if (_appVersion.size()) params.addQueryItem("av", _appVersion); else if (appVersion.size()) params.addQueryItem("av", appVersion); if (screenName.size()) params.addQueryItem("cd", screenName); send_metric(params); }
// event void sendEvent(QString eventCategory = "", QString eventAction = "", QString eventLabel = "", int eventValue = 0) const { QUrl params = build_metric("event"); if (_appName.size()) params.addQueryItem("an", _appName); // mobile event app tracking if (_appVersion.size()) params.addQueryItem("av", _appVersion); // mobile event app tracking if (eventCategory.size()) params.addQueryItem("ec", eventCategory); if (eventAction.size()) params.addQueryItem("ea", eventAction); if (eventLabel.size()) params.addQueryItem("el", eventLabel); if (eventValue) params.addQueryItem("ev", QString::number(eventValue)); send_metric(params); DBG_INFO(QString("%1,%2,%3").arg(eventCategory).arg(eventAction).arg(eventLabel)); }
static int handle_request(void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_data_size, void **con_cls) { int ret; struct MHD_Response *response = NULL; struct brubeck_server *brubeck = cls; if (!strcmp(method, "GET")) { if (!strcmp(url, "/ping")) { char *jsonr; json_t *pong = json_pack("{s:s, s:i, s:s}", "version", "brubeck " GIT_SHA, "pid", (int)getpid(), "status", "OK"); jsonr = json_dumps(pong, JSON_PRESERVE_ORDER); response = MHD_create_response_from_data(strlen(jsonr), jsonr, 1, 0); json_decref(pong); } else if (!strcmp(url, "/stats")) response = send_stats(brubeck); else if (starts_with(url, "/metric/")) response = send_metric(brubeck, url); } else if (!strcmp(method, "POST")) { if (starts_with(url, "/expire/")) response = expire_metric(brubeck, url); } if (!response) { static const char *NOT_FOUND = "404 not found"; response = MHD_create_response_from_data( strlen(NOT_FOUND), (void *)NOT_FOUND, 0, 0); MHD_add_response_header(response, "Connection", "close"); ret = MHD_queue_response(connection, 404, response); } else { MHD_add_response_header(response, "Connection", "close"); MHD_add_response_header(response, "Content-Type", "application/json"); ret = MHD_queue_response(connection, 200, response); } MHD_destroy_response(response); return ret; }
//void startSession(); void endSession() const { QUrl params = build_metric("event"); params.addQueryItem("sc", "end"); send_metric(params); }
// timing void sendTiming(/* todo */) const { QUrl params = build_metric("timing"); //if (appName.size()) params.addQueryItem("an", appName); send_metric(params); }
// exception void sendException(QString exceptionDescription, bool exceptionFatal = true) const { QUrl params = build_metric("exception"); if (exceptionDescription.size()) params.addQueryItem("exd", exceptionDescription); if (!exceptionFatal) params.addQueryItem("exf", "0"); send_metric(params); }
// item void sendItem(QString itemName) const { QUrl params = build_metric("item"); params.addQueryItem("in", itemName); //if (appName.size()) params.addQueryItem("an", appName); send_metric(params); }
// transaction void sendTransaction(QString transactionID, QString transactionAffiliation = "" /*...todo...*/) const { QUrl params = build_metric("transaction"); params.addQueryItem("ti", transactionID); if (transactionAffiliation.size()) params.addQueryItem("ta", transactionAffiliation); send_metric(params); }