mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[ion] Add a telemetry API
This commit is contained in:
13
ion/include/ion/telemetry.h
Normal file
13
ion/include/ion/telemetry.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef ION_TELEMETRY_H
|
||||
#define ION_TELEMETRY_H
|
||||
|
||||
namespace Ion {
|
||||
namespace Telemetry {
|
||||
|
||||
void reportScreen(const char * screenName);
|
||||
void reportEvent(const char * category, const char * action, const char * label);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -12,6 +12,10 @@ ion_src += $(addprefix ion/src/shared/, \
|
||||
events_modifier.cpp \
|
||||
)
|
||||
|
||||
ifeq ($(EPSILON_TELEMETRY),1)
|
||||
ion_src += ion/src/shared/telemetry_console.cpp
|
||||
endif
|
||||
|
||||
# If you need to benchmark execution, you can replace events_keyboard with
|
||||
# events_benchmark.
|
||||
# If you need to profile execution, you can replace events_keyboard with
|
||||
|
||||
16
ion/src/shared/telemetry_console.cpp
Normal file
16
ion/src/shared/telemetry_console.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#include <ion/console.h>
|
||||
#include <ion/telemetry.h>
|
||||
|
||||
void Ion::Telemetry::reportScreen(const char * screenName) {
|
||||
Console::writeLine("TelemetryScreen: ", false);
|
||||
Console::writeLine(screenName);
|
||||
}
|
||||
|
||||
void Ion::Telemetry::reportEvent(const char * category, const char * action, const char * label) {
|
||||
Console::writeLine("TelemetryEvent: ", false);
|
||||
Console::writeLine(category, false);
|
||||
Console::writeLine(", ", false);
|
||||
Console::writeLine(action, false);
|
||||
Console::writeLine(", ", false);
|
||||
Console::writeLine(label);
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
ion_src += $(addprefix ion/src/simulator/android/src/cpp/, \
|
||||
images.cpp \
|
||||
telemetry.cpp \
|
||||
)
|
||||
|
||||
ion_src += $(addprefix ion/src/simulator/shared/, \
|
||||
@@ -8,6 +7,10 @@ ion_src += $(addprefix ion/src/simulator/shared/, \
|
||||
dummy/language.cpp \
|
||||
)
|
||||
|
||||
ifeq ($(EPSILON_TELEMETRY),1)
|
||||
ion_src += ion/src/simulator/android/src/cpp/telemetry.cpp
|
||||
endif
|
||||
|
||||
$(call object_for,ion/src/simulator/shared/main.cpp) : SFLAGS += -DEPSILON_SDL_FULLSCREEN=1
|
||||
|
||||
LDFLAGS += -ljnigraphics -llog
|
||||
|
||||
@@ -1,28 +1,63 @@
|
||||
#include "../../../shared/platform.h"
|
||||
#include "../../../shared/telemetry.h"
|
||||
#include <jni.h>
|
||||
#include <SDL.h>
|
||||
|
||||
void IonSimulatorTelemetryInit() {
|
||||
JNIEnv * env = static_cast<JNIEnv *>(SDL_AndroidGetJNIEnv());
|
||||
jobject activity = static_cast<jobject>(SDL_AndroidGetActivity());
|
||||
static inline JNIEnv * AndroidJNI() {
|
||||
return static_cast<JNIEnv *>(SDL_AndroidGetJNIEnv());
|
||||
}
|
||||
|
||||
static inline jobject AndroidActivity() {
|
||||
return static_cast<jobject>(SDL_AndroidGetActivity())
|
||||
}
|
||||
|
||||
static inline JS(const char * s, JNIEnv * env) {
|
||||
return env->NewStringUTF(s);
|
||||
}
|
||||
|
||||
namespace Ion {
|
||||
namespace Simulator {
|
||||
namespace Telemetry {
|
||||
|
||||
void init() {
|
||||
JNIEnv * env = AndroidJNI();
|
||||
|
||||
jclass j_class = env->FindClass("com/numworks/calculator/EpsilonActivity");
|
||||
jmethodID j_methodId = env->GetMethodID(j_class,"telemetryInit", "()V");
|
||||
|
||||
env->CallVoidMethod(activity, j_methodId);
|
||||
env->CallVoidMethod(AndroidActivity(), j_methodId);
|
||||
}
|
||||
|
||||
void IonSimulatorTelemetryEvent(const char * eventName) {
|
||||
JNIEnv * env = static_cast<JNIEnv *>(SDL_AndroidGetJNIEnv());
|
||||
jobject activity = static_cast<jobject>(SDL_AndroidGetActivity());
|
||||
void shutdown() {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static inline JS(const char * s, JNIEnv * env) {
|
||||
return env->NewStringUTF(s);
|
||||
}
|
||||
|
||||
namespace Ion {
|
||||
namespace Telemetry {
|
||||
|
||||
void reportScreen(const char * screenName) {
|
||||
JNIEnv * env = AndroidJNI();
|
||||
|
||||
jclass j_class = env->FindClass("com/numworks/calculator/EpsilonActivity");
|
||||
jmethodID j_methodId = env->GetMethodID(j_class,"telemetryEvent", "(Ljava/lang/String;)V");
|
||||
jmethodID j_methodId = env->GetMethodID(j_class, "telemetryScreen", "(Ljava/lang/String;)V");
|
||||
|
||||
jstring j_eventName = env->NewStringUTF(eventName);
|
||||
|
||||
env->CallVoidMethod(activity, j_methodId, j_eventName);
|
||||
env->CallVoidMethod(AndroidActivity(), j_methodId, JS(screenName, env));
|
||||
}
|
||||
|
||||
void IonSimulatorTelemetryDeinit() {
|
||||
void reportEvent(const char * category, const char * action, const char * label) {
|
||||
JNIEnv * env = AndroidJNI();
|
||||
|
||||
jclass j_class = env->FindClass("com/numworks/calculator/EpsilonActivity");
|
||||
jmethodID j_methodId = env->GetMethodID(j_class, "telemetryEvent", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
|
||||
|
||||
env->CallVoidMethod(AndroidActivity(), j_methodId, JS(category, env), JS(action, env), JS(label, env));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,8 +48,18 @@ public class EpsilonActivity extends SDLActivity {
|
||||
sTracker = sAnalytics.newTracker("UA-93775823-3");
|
||||
}
|
||||
|
||||
public void telemetryEvent(String eventName) {
|
||||
sTracker.setScreenName(eventName);
|
||||
public void telemetryScreen(String screenName) {
|
||||
sTracker.setScreenName(screenName);
|
||||
sTracker.send(new HitBuilders.ScreenViewBuilder().build());
|
||||
}
|
||||
|
||||
public void telemetryEvent(String category, String action, String label) {
|
||||
sTracker.send(new HitBuilders.EventBuilder()
|
||||
.setCategory(category)
|
||||
.setAction(action)
|
||||
.setLabel(label)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,8 +9,7 @@ ion_src += $(addprefix ion/src/simulator/shared/, \
|
||||
|
||||
$(call object_for,ion/src/simulator/shared/main.cpp) : SFLAGS += -DEPSILON_SDL_FULLSCREEN=1
|
||||
|
||||
GOOGLE_ANALYTICS ?= 1
|
||||
ifeq ($(GOOGLE_ANALYTICS),1)
|
||||
ifeq ($(EPSILON_TELEMETRY),1)
|
||||
# Display a nice error if the Google Analytics SDK is not installed
|
||||
$(call object_for,ion/src/simulator/ios/telemetry.m): ion/src/simulator/ios/GoogleAnalyticsServices/GoogleAnalytics/Library/GAI.h
|
||||
ion/src/simulator/ios/GoogleAnalyticsServices/GoogleAnalytics/Library/GAI.h:
|
||||
@@ -25,8 +24,6 @@ LDFLAGS += -lz
|
||||
LDFLAGS += -framework SystemConfiguration
|
||||
LDFLAGS += -framework CoreData
|
||||
LDFLAGS += -Lion/src/simulator/ios/GoogleAnalyticsServices
|
||||
else
|
||||
ion_src += ion/src/simulator/shared/dummy/telemetry.cpp
|
||||
endif
|
||||
|
||||
# App resources
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
#include "../shared/platform.h"
|
||||
|
||||
#import <GAI.h>
|
||||
#import <GAIDictionaryBuilder.h>
|
||||
#import <GAIFields.h>
|
||||
|
||||
void IonSimulatorTelemetryInit() {
|
||||
[[GAI sharedInstance] trackerWithTrackingId:@"UA-93775823-3"];
|
||||
}
|
||||
|
||||
void IonSimulatorTelemetryEvent(const char * eventName) {
|
||||
id<GAITracker> tracker = [GAI sharedInstance].defaultTracker;
|
||||
[tracker set:kGAIScreenName value:[NSString stringWithUTF8String:eventName]];
|
||||
[tracker send:[[GAIDictionaryBuilder createScreenView] build]];
|
||||
}
|
||||
|
||||
void IonSimulatorTelemetryDeinit() {
|
||||
}
|
||||
48
ion/src/simulator/ios/telemetry.mm
Normal file
48
ion/src/simulator/ios/telemetry.mm
Normal file
@@ -0,0 +1,48 @@
|
||||
#include "../shared/telemetry.h"
|
||||
|
||||
#import <GAI.h>
|
||||
#import <GAIDictionaryBuilder.h>
|
||||
#import <GAIFields.h>
|
||||
|
||||
class Ion {
|
||||
class Simulator {
|
||||
class Telemetry {
|
||||
|
||||
void init() {
|
||||
[[GAI sharedInstance] trackerWithTrackingId:@"UA-93775823-3"];
|
||||
}
|
||||
void shutdown() {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static inline NSString * NS(const char * s) {
|
||||
if (s != nullptr) {
|
||||
return [NSString stringWithUTF8String:s];
|
||||
} else {
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
|
||||
class Ion {
|
||||
class Telemetry {
|
||||
|
||||
void reportScreen(const char * screenName) {
|
||||
id<GAITracker> tracker = [GAI sharedInstance].defaultTracker;
|
||||
[tracker set:kGAIScreenName value:NS(screenName)];
|
||||
[tracker send:[[GAIDictionaryBuilder createScreenView] build]];
|
||||
}
|
||||
|
||||
void reportEvent(const char * category, const char * action, const char * label) {
|
||||
id<GAITracker> tracker = [GAI sharedInstance].defaultTracker;
|
||||
[tracker send:[[GAIDictionaryBuilder
|
||||
createEventWithCategory:NS(category)
|
||||
action:NS(action)
|
||||
label:NS(label)
|
||||
value:nil] build]];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,11 @@ ion_src += $(addprefix ion/src/simulator/linux/, \
|
||||
|
||||
ion_src += $(addprefix ion/src/simulator/shared/, \
|
||||
dummy/callback.cpp \
|
||||
dummy/telemetry.cpp \
|
||||
)
|
||||
|
||||
ifeq ($(EPSILON_TELEMETRY),1)
|
||||
ion_src += ion/src/simulator/shared/dummy/telemetry_init.cpp
|
||||
ion_src += ion/src/shared/telemetry_console.cpp
|
||||
endif
|
||||
|
||||
LDFLAGS += -ljpeg
|
||||
|
||||
@@ -5,9 +5,13 @@ ion_src += $(addprefix ion/src/simulator/macos/, \
|
||||
ion_src += $(addprefix ion/src/simulator/shared/, \
|
||||
apple/language.m \
|
||||
dummy/callback.cpp \
|
||||
dummy/telemetry.cpp \
|
||||
)
|
||||
|
||||
ifeq ($(EPSILON_TELEMETRY),1)
|
||||
ion_src += ion/src/simulator/shared/dummy/telemetry_init.cpp
|
||||
ion_src += ion/src/shared/telemetry_console.cpp
|
||||
endif
|
||||
|
||||
# App resources
|
||||
|
||||
SIMULATOR_ICON_SIZES = 16x16 32x32 64x64 128x128 256x256 512x512 1024x1024
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
#include "../platform.h"
|
||||
|
||||
void IonSimulatorTelemetryInit() {
|
||||
}
|
||||
|
||||
void IonSimulatorTelemetryEvent(const char * eventName) {
|
||||
}
|
||||
|
||||
void IonSimulatorTelemetryDeinit() {
|
||||
}
|
||||
15
ion/src/simulator/shared/dummy/telemetry_init.cpp
Normal file
15
ion/src/simulator/shared/dummy/telemetry_init.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#include "../platform.h"
|
||||
|
||||
namespace Ion {
|
||||
namespace Simulator {
|
||||
namespace Telemetry {
|
||||
|
||||
void init() {
|
||||
}
|
||||
|
||||
void shutdown() {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -209,10 +209,6 @@ Event getPlatformEvent() {
|
||||
if (event.type == SDL_TEXTINPUT) {
|
||||
return eventFromSDLTextInputEvent(event.text);
|
||||
}
|
||||
if (event.type == SDL_APP_WILLENTERFOREGROUND) {
|
||||
IonSimulatorTelemetryEvent("Calculator");
|
||||
return None;
|
||||
}
|
||||
}
|
||||
return None;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#if !EPSILON_SDL_SCREEN_ONLY
|
||||
#include "layout.h"
|
||||
#endif
|
||||
#include "telemetry.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <ion.h>
|
||||
@@ -25,12 +26,15 @@ int main(int argc, char * argv[]) {
|
||||
arguments.push_back(language);
|
||||
}
|
||||
|
||||
IonSimulatorTelemetryInit();
|
||||
#if EPSILON_TELEMETRY
|
||||
Ion::Simulator::Telemetry::init();
|
||||
#endif
|
||||
Ion::Simulator::Main::init();
|
||||
IonSimulatorTelemetryEvent("Calculator");
|
||||
ion_main(arguments.size(), &arguments[0]);
|
||||
Ion::Simulator::Main::quit();
|
||||
IonSimulatorTelemetryDeinit();
|
||||
#if EPSILON_TELEMETRY
|
||||
Ion::Simulator::Telemetry::shutdown();
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -13,10 +13,6 @@ extern "C" {
|
||||
SDL_Texture * IonSimulatorLoadImage(SDL_Renderer * renderer, const char * identifier);
|
||||
char * IonSimulatorGetLanguageCode();
|
||||
|
||||
void IonSimulatorTelemetryInit();
|
||||
void IonSimulatorTelemetryEvent(const char * eventName);
|
||||
void IonSimulatorTelemetryDeinit();
|
||||
|
||||
#if EPSILON_SDL_SCREEN_ONLY
|
||||
|
||||
void IonSimulatorKeyboardKeyDown(int keyNumber);
|
||||
|
||||
17
ion/src/simulator/shared/telemetry.h
Normal file
17
ion/src/simulator/shared/telemetry.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef ION_SIMULATOR_TELEMETRY_H
|
||||
#define ION_SIMULATOR_TELEMETRY_H
|
||||
|
||||
#include <ion/telemetry.h>
|
||||
|
||||
namespace Ion {
|
||||
namespace Simulator {
|
||||
namespace Telemetry {
|
||||
|
||||
void init();
|
||||
void shutdown();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -17,9 +17,13 @@ ion_src += $(addprefix ion/src/simulator/web/, \
|
||||
|
||||
ion_src += $(addprefix ion/src/simulator/shared/, \
|
||||
dummy/language.cpp \
|
||||
dummy/telemetry.cpp \
|
||||
)
|
||||
|
||||
ifeq ($(EPSILON_TELEMETRY),1)
|
||||
ion_src += ion/src/simulator/shared/dummy/telemetry_init.cpp
|
||||
ion_src += ion/src/shared/telemetry_console.cpp
|
||||
endif
|
||||
|
||||
DEFAULT = $(BUILD_DIR)/simulator.zip
|
||||
|
||||
$(BUILD_DIR)/simulator.zip: $(BUILD_DIR)/epsilon.packed.js
|
||||
|
||||
@@ -6,7 +6,11 @@ ion_src += $(addprefix ion/src/simulator/windows/, \
|
||||
|
||||
ion_src += $(addprefix ion/src/simulator/shared/, \
|
||||
dummy/callback.cpp \
|
||||
dummy/telemetry.cpp \
|
||||
)
|
||||
|
||||
ifeq ($(EPSILON_TELEMETRY),1)
|
||||
ion_src += ion/src/simulator/shared/dummy/telemetry_init.cpp
|
||||
ion_src += ion/src/shared/telemetry_console.cpp
|
||||
endif
|
||||
|
||||
LDFLAGS += -lgdiplus
|
||||
|
||||
Reference in New Issue
Block a user