@@ -473,6 +473,56 @@ namespace gameanalytics
473473 }
474474 }
475475
476+ void GAEvents::addLevelEvent (EGALevelStatus status, int id, std::string const & name, int value, const json& fields)
477+ {
478+ try
479+ {
480+ if (!state::GAState::isEventSubmissionEnabled ())
481+ {
482+ return ;
483+ }
484+
485+ if (!state::GAState::getInstance ().updateLevelContext (status, id, name))
486+ {
487+ logging::GALogger::e (" Invalid level" );
488+ return ;
489+ }
490+
491+ // Validate
492+ validators::ValidationResult validationResult = validators::GAValidator::validateLevelEvent (status, id, name);
493+ if (!validationResult.result )
494+ {
495+ http::GAHTTPApi& httpInstance = http::GAHTTPApi::getInstance ();
496+ httpInstance.sendSdkErrorEvent (validationResult.category , validationResult.area , validationResult.action , validationResult.parameter , validationResult.reason , state::GAState::getGameKey (), state::GAState::getGameSecret ());
497+ return ;
498+ }
499+
500+ // Create empty eventData
501+ json eventData;
502+ eventData[" category" ] = GAEvents::CategoryLevel;
503+ eventData[" status" ] = levelStatusString (status);
504+ eventData[" level_id" ] = id;
505+ eventData[" level_name" ] = name;
506+ eventData[" value" ] = value;
507+
508+ json cleanedFields = state::GAState::getValidatedCustomFields (fields);
509+ getInstance ().addCustomFieldsToEvent (eventData, cleanedFields);
510+
511+ // Add custom dimensions
512+ getInstance ().addDimensionsToEvent (eventData);
513+
514+ // Log
515+ logging::GALogger::i (" Add LEVEL event: %s" , eventData.dump ().c_str ());
516+
517+ // Send to store
518+ getInstance ().addEventToStore (eventData);
519+ }
520+ catch (std::exception& e)
521+ {
522+ logging::GALogger::e (" addLevelEvent - Exception thrown: %s" , e.what ());
523+ }
524+ }
525+
476526 void GAEvents::processEventQueue ()
477527 {
478528 processEvents (" " , true );
@@ -590,36 +640,7 @@ namespace gameanalytics
590640 http::EGAHTTPApiResponse responseEnum;
591641 http::GAHTTPApi& http = http::GAHTTPApi::getInstance ();
592642
593- #if USE_UWP && defined(USE_UWP_HTTP)
594- std::pair<http::EGAHTTPApiResponse, std::string> pair;
595-
596- try
597- {
598- pair = http->sendEventsInArray (payloadArray).get ();
599- }
600- catch (Platform::COMException^ e)
601- {
602- pair = std::pair<http::EGAHTTPApiResponse, std::string>(http::NoResponse, " " );
603- }
604- responseEnum = pair.first ;
605-
606- if (pair.second .size () > 0 )
607- {
608- try
609- {
610- json d = json::parse (pair.second );
611- dataDict.merge_patch (d);
612- }
613- catch (const json::exception& e)
614- {
615- logging::GALogger::d (" processEvents -- JSON error: %s" , e.what ());
616- logging::GALogger::d (" %s" , pair.second .c_str ());
617- }
618- }
619- #else
620643 responseEnum = http.sendEventsInArray (dataDict, payloadArray);
621- #endif
622-
623644 if (responseEnum == http::Ok)
624645 {
625646 // Delete events
0 commit comments