diff --git a/project/the_gates/scripts/analytics/analytics.gd b/project/the_gates/scripts/analytics/analytics.gd index 0ce5119..4175095 100644 --- a/project/the_gates/scripts/analytics/analytics.gd +++ b/project/the_gates/scripts/analytics/analytics.gd @@ -14,11 +14,6 @@ func _ready() -> void: add_child(sender) -func _exit_tree() -> void: - for sender in analytics_senders: - sender.exit() - - func send_event(body: Dictionary = {}) -> void: var url = backend.analytics_event var callback = func(_result, code, _headers, _body): @@ -33,7 +28,6 @@ func get_user_id() -> void: var callback = func(_result, code, _headers, body): if code == 200: AnalyticsEvents.user_id = body.get_string_from_utf8() - Debug.logr("User id recieved: " + AnalyticsEvents.user_id) else: Debug.logerr("Request get_user_id failed. Code " + str(code)) var err = await request(url, callback) diff --git a/project/the_gates/scripts/analytics/analytics_sender_app.gd b/project/the_gates/scripts/analytics/analytics_sender_app.gd index 1f66adb..5d77c8f 100644 --- a/project/the_gates/scripts/analytics/analytics_sender_app.gd +++ b/project/the_gates/scripts/analytics/analytics_sender_app.gd @@ -8,6 +8,12 @@ var heartbeat_timer: Timer func _ready() -> void: Analytics.send_event(AnalyticsEvents.app_open()) start_heartbeat() + + # Send latest exit event + var json: String = DataSaver.get_string("analytics", "app_exit") + if json.is_empty(): return + DataSaver.set_value("analytics", "app_exit", "") + Analytics.send_event(JSON.parse_string(json)) func start_heartbeat() -> void: @@ -22,6 +28,8 @@ func send_hearbeat() -> void: Analytics.send_event(AnalyticsEvents.heartbeat(time_spend)) -func exit() -> void: +func _exit_tree() -> void: + # Save to send on open var time_spend = int(Time.get_ticks_msec() / 1000) - Analytics.send_event(AnalyticsEvents.app_exit(time_spend)) + var event = AnalyticsEvents.app_exit(time_spend) + DataSaver.set_value("analytics", "app_exit", JSON.stringify(event)) diff --git a/project/the_gates/scripts/analytics/analytics_sender_gate.gd b/project/the_gates/scripts/analytics/analytics_sender_gate.gd index aec8235..41d89cf 100644 --- a/project/the_gates/scripts/analytics/analytics_sender_gate.gd +++ b/project/the_gates/scripts/analytics/analytics_sender_gate.gd @@ -11,6 +11,12 @@ func _ready() -> void: gate_events.open_gate.connect(send_gate_open) gate_events.gate_entered.connect(send_gate_enter) gate_events.exit_gate.connect(send_gate_exit) + + # Send latest exit event + var json: String = DataSaver.get_string("analytics", "send_gate_exit") + if json.is_empty(): return + DataSaver.set_value("analytics", "send_gate_exit", "") + Analytics.send_event(JSON.parse_string(json)) func send_gate_open(url: String) -> void: @@ -31,6 +37,10 @@ func send_gate_exit() -> void: gate_url = "" -func exit() -> void: +func _exit_tree() -> void: if gate_url.is_empty(): return - send_gate_exit() + + # Save to send on open + var time_spend = int(Time.get_ticks_msec() / 1000) - gate_open_time + var event = AnalyticsEvents.gate_exit(gate_url, time_spend) + DataSaver.set_value("analytics", "send_gate_exit", JSON.stringify(event)) diff --git a/project/the_gates/scripts/data_saver.gd b/project/the_gates/scripts/data_saver.gd index c494e17..9149680 100644 --- a/project/the_gates/scripts/data_saver.gd +++ b/project/the_gates/scripts/data_saver.gd @@ -1,4 +1,5 @@ extends ConfigBase +#class_name DataSaver var path: String = "user://resources/data_saver.cfg" diff --git a/project/the_gates/scripts/loading/config_base.gd b/project/the_gates/scripts/loading/config_base.gd index 5bef43f..3086200 100644 --- a/project/the_gates/scripts/loading/config_base.gd +++ b/project/the_gates/scripts/loading/config_base.gd @@ -15,7 +15,7 @@ func get_string(section: String, key: String) -> String: var value: String if config.has_section_key(section, key): value = config.get_value(section, key) - Debug.logr(key + "=" + value) +# Debug.logr(key + "=" + value) else: Debug.logclr("don't have section " + section + ", key " + key, Color.YELLOW) return value @@ -24,7 +24,7 @@ func get_value(section: String, key: String): var value if config.has_section_key(section, key): value = config.get_value(section, key) - Debug.logr(key + "=" + str(value)) +# Debug.logr(key + "=" + str(value)) else: Debug.logclr("don't have section " + section + ", key " + key, Color.YELLOW) return value @@ -37,7 +37,7 @@ func get_section_keys(section: String) -> PackedStringArray: var keys: PackedStringArray if config.has_section(section): keys = config.get_section_keys(section) - Debug.logr(keys) +# Debug.logr(keys) else: Debug.logclr("don't have section " + section, Color.YELLOW) return keys