mirror of
https://github.com/thegatesbrowser/thegates.git
synced 2025-08-23 08:17:34 -04:00
send exit events on startup
This commit is contained in:
parent
7f8d67f6f4
commit
a5fe259dce
5 changed files with 26 additions and 13 deletions
|
@ -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)
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
extends ConfigBase
|
||||
#class_name DataSaver
|
||||
|
||||
var path: String = "user://resources/data_saver.cfg"
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue