diff --git a/ion/include/ion/telemetry.h b/ion/include/ion/telemetry.h new file mode 100644 index 000000000..ea7693720 --- /dev/null +++ b/ion/include/ion/telemetry.h @@ -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 diff --git a/ion/src/device/Makefile b/ion/src/device/Makefile index 161218a49..56d222ecc 100644 --- a/ion/src/device/Makefile +++ b/ion/src/device/Makefile @@ -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 diff --git a/ion/src/shared/telemetry_console.cpp b/ion/src/shared/telemetry_console.cpp new file mode 100644 index 000000000..13e222e4e --- /dev/null +++ b/ion/src/shared/telemetry_console.cpp @@ -0,0 +1,16 @@ +#include +#include + +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); +} diff --git a/ion/src/simulator/android/Makefile b/ion/src/simulator/android/Makefile index 04d8dad46..ec4cb714a 100644 --- a/ion/src/simulator/android/Makefile +++ b/ion/src/simulator/android/Makefile @@ -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 diff --git a/ion/src/simulator/android/src/cpp/telemetry.cpp b/ion/src/simulator/android/src/cpp/telemetry.cpp index 62e7b8967..ddd815f27 100644 --- a/ion/src/simulator/android/src/cpp/telemetry.cpp +++ b/ion/src/simulator/android/src/cpp/telemetry.cpp @@ -1,28 +1,63 @@ -#include "../../../shared/platform.h" +#include "../../../shared/telemetry.h" #include #include -void IonSimulatorTelemetryInit() { - JNIEnv * env = static_cast(SDL_AndroidGetJNIEnv()); - jobject activity = static_cast(SDL_AndroidGetActivity()); +static inline JNIEnv * AndroidJNI() { + return static_cast(SDL_AndroidGetJNIEnv()); +} + +static inline jobject AndroidActivity() { + return static_cast(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(SDL_AndroidGetJNIEnv()); - jobject activity = static_cast(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)); +} + +} } diff --git a/ion/src/simulator/android/src/java/com/numworks/calculator/EpsilonActivity.java b/ion/src/simulator/android/src/java/com/numworks/calculator/EpsilonActivity.java index eef6676f8..23301615e 100644 --- a/ion/src/simulator/android/src/java/com/numworks/calculator/EpsilonActivity.java +++ b/ion/src/simulator/android/src/java/com/numworks/calculator/EpsilonActivity.java @@ -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() + ); + } + } diff --git a/ion/src/simulator/ios/Makefile b/ion/src/simulator/ios/Makefile index 9d0cefed7..876963d03 100644 --- a/ion/src/simulator/ios/Makefile +++ b/ion/src/simulator/ios/Makefile @@ -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 diff --git a/ion/src/simulator/ios/telemetry.m b/ion/src/simulator/ios/telemetry.m deleted file mode 100644 index 8b7af6b40..000000000 --- a/ion/src/simulator/ios/telemetry.m +++ /dev/null @@ -1,18 +0,0 @@ -#include "../shared/platform.h" - -#import -#import -#import - -void IonSimulatorTelemetryInit() { - [[GAI sharedInstance] trackerWithTrackingId:@"UA-93775823-3"]; -} - -void IonSimulatorTelemetryEvent(const char * eventName) { - id tracker = [GAI sharedInstance].defaultTracker; - [tracker set:kGAIScreenName value:[NSString stringWithUTF8String:eventName]]; - [tracker send:[[GAIDictionaryBuilder createScreenView] build]]; -} - -void IonSimulatorTelemetryDeinit() { -} diff --git a/ion/src/simulator/ios/telemetry.mm b/ion/src/simulator/ios/telemetry.mm new file mode 100644 index 000000000..87d0de708 --- /dev/null +++ b/ion/src/simulator/ios/telemetry.mm @@ -0,0 +1,48 @@ +#include "../shared/telemetry.h" + +#import +#import +#import + +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 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 tracker = [GAI sharedInstance].defaultTracker; + [tracker send:[[GAIDictionaryBuilder + createEventWithCategory:NS(category) + action:NS(action) + label:NS(label) + value:nil] build]]; +} + +} +} diff --git a/ion/src/simulator/linux/Makefile b/ion/src/simulator/linux/Makefile index 409bdd0d9..f6cae470e 100644 --- a/ion/src/simulator/linux/Makefile +++ b/ion/src/simulator/linux/Makefile @@ -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 diff --git a/ion/src/simulator/macos/Makefile b/ion/src/simulator/macos/Makefile index 1541fc330..ae25b03f3 100644 --- a/ion/src/simulator/macos/Makefile +++ b/ion/src/simulator/macos/Makefile @@ -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 diff --git a/ion/src/simulator/shared/dummy/telemetry.cpp b/ion/src/simulator/shared/dummy/telemetry.cpp deleted file mode 100644 index aa1dff5f0..000000000 --- a/ion/src/simulator/shared/dummy/telemetry.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "../platform.h" - -void IonSimulatorTelemetryInit() { -} - -void IonSimulatorTelemetryEvent(const char * eventName) { -} - -void IonSimulatorTelemetryDeinit() { -} diff --git a/ion/src/simulator/shared/dummy/telemetry_init.cpp b/ion/src/simulator/shared/dummy/telemetry_init.cpp new file mode 100644 index 000000000..fc5e096e3 --- /dev/null +++ b/ion/src/simulator/shared/dummy/telemetry_init.cpp @@ -0,0 +1,15 @@ +#include "../platform.h" + +namespace Ion { +namespace Simulator { +namespace Telemetry { + +void init() { +} + +void shutdown() { +} + +} +} +} diff --git a/ion/src/simulator/shared/events_keyboard.cpp b/ion/src/simulator/shared/events_keyboard.cpp index bba3fe92b..02bd8b4a1 100644 --- a/ion/src/simulator/shared/events_keyboard.cpp +++ b/ion/src/simulator/shared/events_keyboard.cpp @@ -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; } diff --git a/ion/src/simulator/shared/main_sdl.cpp b/ion/src/simulator/shared/main_sdl.cpp index ac714addb..9279dc0f1 100644 --- a/ion/src/simulator/shared/main_sdl.cpp +++ b/ion/src/simulator/shared/main_sdl.cpp @@ -4,6 +4,7 @@ #if !EPSILON_SDL_SCREEN_ONLY #include "layout.h" #endif +#include "telemetry.h" #include #include @@ -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; } diff --git a/ion/src/simulator/shared/platform.h b/ion/src/simulator/shared/platform.h index 4b8e461cb..0dcb4e74c 100644 --- a/ion/src/simulator/shared/platform.h +++ b/ion/src/simulator/shared/platform.h @@ -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); diff --git a/ion/src/simulator/shared/telemetry.h b/ion/src/simulator/shared/telemetry.h new file mode 100644 index 000000000..d959d1b1e --- /dev/null +++ b/ion/src/simulator/shared/telemetry.h @@ -0,0 +1,17 @@ +#ifndef ION_SIMULATOR_TELEMETRY_H +#define ION_SIMULATOR_TELEMETRY_H + +#include + +namespace Ion { +namespace Simulator { +namespace Telemetry { + +void init(); +void shutdown(); + +} +} +} + +#endif diff --git a/ion/src/simulator/web/Makefile b/ion/src/simulator/web/Makefile index 6a8bab199..ada734ed7 100644 --- a/ion/src/simulator/web/Makefile +++ b/ion/src/simulator/web/Makefile @@ -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 diff --git a/ion/src/simulator/windows/Makefile b/ion/src/simulator/windows/Makefile index 3256077c5..897db8dca 100644 --- a/ion/src/simulator/windows/Makefile +++ b/ion/src/simulator/windows/Makefile @@ -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