analytics to scene

This commit is contained in:
Nordup 2023-06-05 23:32:11 +03:00
parent 992ccc9307
commit 4885e68142
28 changed files with 85 additions and 53 deletions

View file

Before

Width:  |  Height:  |  Size: 351 KiB

After

Width:  |  Height:  |  Size: 351 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

Before After
Before After

View file

@ -3,15 +3,15 @@
importer="texture" importer="texture"
type="CompressedTexture2D" type="CompressedTexture2D"
uid="uid://dyenb2x6xyguv" uid="uid://dyenb2x6xyguv"
path="res://.godot/imported/icon.svg-3629612f1967f9e645af99eed2b8b758.ctex" path="res://.godot/imported/icon.svg-f3959d09c40a20b6aa50d6b4ce0c6c4f.ctex"
metadata={ metadata={
"vram_texture": false "vram_texture": false
} }
[deps] [deps]
source_file="res://icons/icon.svg" source_file="res://app_icon/icon.svg"
dest_files=["res://.godot/imported/icon.svg-3629612f1967f9e645af99eed2b8b758.ctex"] dest_files=["res://.godot/imported/icon.svg-f3959d09c40a20b6aa50d6b4ce0c6c4f.ctex"]
[params] [params]

View file

Before

Width:  |  Height:  |  Size: 4.9 KiB

After

Width:  |  Height:  |  Size: 4.9 KiB

Before After
Before After

View file

@ -3,15 +3,15 @@
importer="texture" importer="texture"
type="CompressedTexture2D" type="CompressedTexture2D"
uid="uid://b6obl18d4rst8" uid="uid://b6obl18d4rst8"
path="res://.godot/imported/icon_128.png-7b670f2a1988062bd4bcbae55c30d151.ctex" path="res://.godot/imported/icon_128.png-dd149ee4a813c6f15a713cf4e76f2636.ctex"
metadata={ metadata={
"vram_texture": false "vram_texture": false
} }
[deps] [deps]
source_file="res://icons/icon_128.png" source_file="res://app_icon/icon_128.png"
dest_files=["res://.godot/imported/icon_128.png-7b670f2a1988062bd4bcbae55c30d151.ctex"] dest_files=["res://.godot/imported/icon_128.png-dd149ee4a813c6f15a713cf4e76f2636.ctex"]
[params] [params]

View file

Before

Width:  |  Height:  |  Size: 606 B

After

Width:  |  Height:  |  Size: 606 B

Before After
Before After

View file

@ -3,15 +3,15 @@
importer="texture" importer="texture"
type="CompressedTexture2D" type="CompressedTexture2D"
uid="uid://cabc07y323y18" uid="uid://cabc07y323y18"
path="res://.godot/imported/icon_16.png-80a566735a7476bed41af01c64117e09.ctex" path="res://.godot/imported/icon_16.png-114e9c962c662dd89e2e26b3fda184b9.ctex"
metadata={ metadata={
"vram_texture": false "vram_texture": false
} }
[deps] [deps]
source_file="res://icons/icon_16.png" source_file="res://app_icon/icon_16.png"
dest_files=["res://.godot/imported/icon_16.png-80a566735a7476bed41af01c64117e09.ctex"] dest_files=["res://.godot/imported/icon_16.png-114e9c962c662dd89e2e26b3fda184b9.ctex"]
[params] [params]

View file

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Before After
Before After

View file

@ -3,15 +3,15 @@
importer="texture" importer="texture"
type="CompressedTexture2D" type="CompressedTexture2D"
uid="uid://df1poxvhgjkqc" uid="uid://df1poxvhgjkqc"
path="res://.godot/imported/icon_256.png-8716b0979df608f1d0d0d31dec4389c6.ctex" path="res://.godot/imported/icon_256.png-f15d0e566f1aa7fd612a4e9288f230c6.ctex"
metadata={ metadata={
"vram_texture": false "vram_texture": false
} }
[deps] [deps]
source_file="res://icons/icon_256.png" source_file="res://app_icon/icon_256.png"
dest_files=["res://.godot/imported/icon_256.png-8716b0979df608f1d0d0d31dec4389c6.ctex"] dest_files=["res://.godot/imported/icon_256.png-f15d0e566f1aa7fd612a4e9288f230c6.ctex"]
[params] [params]

View file

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Before After
Before After

View file

@ -3,15 +3,15 @@
importer="texture" importer="texture"
type="CompressedTexture2D" type="CompressedTexture2D"
uid="uid://b34pepmam8xma" uid="uid://b34pepmam8xma"
path="res://.godot/imported/icon_32.png-5c7255d1f89e29a56ca4599b98b847ea.ctex" path="res://.godot/imported/icon_32.png-22ff4c1638b937182c8c48e9e54ecd00.ctex"
metadata={ metadata={
"vram_texture": false "vram_texture": false
} }
[deps] [deps]
source_file="res://icons/icon_32.png" source_file="res://app_icon/icon_32.png"
dest_files=["res://.godot/imported/icon_32.png-5c7255d1f89e29a56ca4599b98b847ea.ctex"] dest_files=["res://.godot/imported/icon_32.png-22ff4c1638b937182c8c48e9e54ecd00.ctex"]
[params] [params]

View file

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

Before After
Before After

View file

@ -3,15 +3,15 @@
importer="texture" importer="texture"
type="CompressedTexture2D" type="CompressedTexture2D"
uid="uid://4islpl4ygsxu" uid="uid://4islpl4ygsxu"
path="res://.godot/imported/icon_48.png-3f9bd8247f6e71b8fa56a2fb87dc7ef0.ctex" path="res://.godot/imported/icon_48.png-b9419b8036bb3d47c1d5cd47a8cdbf6d.ctex"
metadata={ metadata={
"vram_texture": false "vram_texture": false
} }
[deps] [deps]
source_file="res://icons/icon_48.png" source_file="res://app_icon/icon_48.png"
dest_files=["res://.godot/imported/icon_48.png-3f9bd8247f6e71b8fa56a2fb87dc7ef0.ctex"] dest_files=["res://.godot/imported/icon_48.png-b9419b8036bb3d47c1d5cd47a8cdbf6d.ctex"]
[params] [params]

View file

Before

Width:  |  Height:  |  Size: 2.4 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB

Before After
Before After

View file

@ -3,15 +3,15 @@
importer="texture" importer="texture"
type="CompressedTexture2D" type="CompressedTexture2D"
uid="uid://bspjfnilokiqb" uid="uid://bspjfnilokiqb"
path="res://.godot/imported/icon_64.png-9cfd4462258d4245d34028d603278f33.ctex" path="res://.godot/imported/icon_64.png-c35eee1ed6b5f2fe2c5000b91086f71d.ctex"
metadata={ metadata={
"vram_texture": false "vram_texture": false
} }
[deps] [deps]
source_file="res://icons/icon_64.png" source_file="res://app_icon/icon_64.png"
dest_files=["res://.godot/imported/icon_64.png-9cfd4462258d4245d34028d603278f33.ctex"] dest_files=["res://.godot/imported/icon_64.png-c35eee1ed6b5f2fe2c5000b91086f71d.ctex"]
[params] [params]

View file

@ -77,8 +77,8 @@ codesign/digest_algorithm=1
codesign/description="" codesign/description=""
codesign/custom_options=PackedStringArray() codesign/custom_options=PackedStringArray()
application/modify_resources=true application/modify_resources=true
application/icon="res://the_gates/icons/icon.ico" application/icon="res://app_icon/icon.ico"
application/console_wrapper_icon="res://the_gates/icons/icon.ico" application/console_wrapper_icon="res://app_icon/icon.ico"
application/icon_interpolation=4 application/icon_interpolation=4
application/file_version="" application/file_version=""
application/product_version="0.3.0" application/product_version="0.3.0"

View file

@ -17,7 +17,7 @@ config/features=PackedStringArray("4.0")
run/max_fps=60 run/max_fps=60
boot_splash/image="res://textures/background.png" boot_splash/image="res://textures/background.png"
boot_splash/fullsize=false boot_splash/fullsize=false
config/icon="res://icons/icon_64.png" config/icon="res://app_icon/icon_64.png"
config/windows_native_icon="res://icons/icon.ico" config/windows_native_icon="res://icons/icon.ico"
[autoload] [autoload]
@ -25,7 +25,6 @@ config/windows_native_icon="res://icons/icon.ico"
DataSaver="*res://scripts/data_saver.gd" DataSaver="*res://scripts/data_saver.gd"
FileDownloader="*res://scripts/loading/file_downloader.gd" FileDownloader="*res://scripts/loading/file_downloader.gd"
Debug="*res://scripts/debug-log/debug.gd" Debug="*res://scripts/debug-log/debug.gd"
Analytics="*res://scripts/analytics/analytics.gd"
AnalyticsEvents="*res://scripts/analytics/analytics_events.gd" AnalyticsEvents="*res://scripts/analytics/analytics_events.gd"
[debug] [debug]

View file

@ -1,6 +1,6 @@
[gd_resource type="Resource" script_class="BackendSettings" load_steps=2 format=3 uid="uid://cjcdum6fm4ta0"] [gd_resource type="Resource" script_class="BackendSettings" load_steps=2 format=3 uid="uid://cjcdum6fm4ta0"]
[ext_resource type="Script" path="res://scripts/analytics/backend.gd" id="1_6ck4k"] [ext_resource type="Script" path="res://scripts/resources/backend.gd" id="1_6ck4k"]
[resource] [resource]
script = ExtResource("1_6ck4k") script = ExtResource("1_6ck4k")

View file

@ -1,12 +1,17 @@
[gd_scene load_steps=8 format=3 uid="uid://ct8gsph3wnepl"] [gd_scene load_steps=13 format=3 uid="uid://ct8gsph3wnepl"]
[ext_resource type="Script" path="res://scripts/app.gd" id="1_skc7d"] [ext_resource type="Script" path="res://scripts/app.gd" id="1_skc7d"]
[ext_resource type="Resource" uid="uid://b1xvdym0qh6td" path="res://resources/gate_events.res" id="2_cdryv"] [ext_resource type="Resource" uid="uid://b1xvdym0qh6td" path="res://resources/gate_events.res" id="2_cdryv"]
[ext_resource type="PackedScene" uid="uid://5btb7nvgmfhl" path="res://scenes/menu.tscn" id="3_o1f7b"] [ext_resource type="PackedScene" uid="uid://5btb7nvgmfhl" path="res://scenes/menu.tscn" id="3_o1f7b"]
[ext_resource type="PackedScene" uid="uid://kywrsqro3d5i" path="res://scenes/world.tscn" id="4_cmlvo"] [ext_resource type="PackedScene" uid="uid://kywrsqro3d5i" path="res://scenes/world.tscn" id="4_cmlvo"]
[ext_resource type="Script" path="res://scripts/bookmark_saver.gd" id="5_ev0ch"] [ext_resource type="Script" path="res://scripts/bookmark_saver.gd" id="5_ev0ch"]
[ext_resource type="Script" path="res://scripts/analytics/analytics.gd" id="6_25d48"]
[ext_resource type="Resource" uid="uid://bewhdj6jugt6q" path="res://resources/bookmarks.tres" id="6_rupvx"] [ext_resource type="Resource" uid="uid://bewhdj6jugt6q" path="res://resources/bookmarks.tres" id="6_rupvx"]
[ext_resource type="PackedScene" uid="uid://byrcbqat0n2px" path="res://scenes/debug.tscn" id="7_3xeb8"] [ext_resource type="PackedScene" uid="uid://byrcbqat0n2px" path="res://scenes/debug.tscn" id="7_3xeb8"]
[ext_resource type="Script" path="res://scripts/analytics/analytics_sender_app.gd" id="7_5328b"]
[ext_resource type="Resource" uid="uid://cjcdum6fm4ta0" path="res://resources/backend.tres" id="7_yykjj"]
[ext_resource type="Script" path="res://scripts/analytics/analytics_sender_error.gd" id="8_ah58q"]
[ext_resource type="Script" path="res://scripts/analytics/analytics_sender_gate.gd" id="9_egxpy"]
[node name="App" type="Node"] [node name="App" type="Node"]
script = ExtResource("1_skc7d") script = ExtResource("1_skc7d")
@ -16,6 +21,20 @@ world_scene = ExtResource("4_cmlvo")
[node name="Debug" parent="." instance=ExtResource("7_3xeb8")] [node name="Debug" parent="." instance=ExtResource("7_3xeb8")]
[node name="Analytics" type="Node" parent="."]
script = ExtResource("6_25d48")
backend = ExtResource("7_yykjj")
[node name="SenderApp" type="Node" parent="Analytics"]
script = ExtResource("7_5328b")
[node name="SenderError" type="Node" parent="Analytics"]
script = ExtResource("8_ah58q")
[node name="SenderGate" type="Node" parent="Analytics"]
script = ExtResource("9_egxpy")
gate_events = ExtResource("2_cdryv")
[node name="BookmarkSaver" type="Node" parent="."] [node name="BookmarkSaver" type="Node" parent="."]
script = ExtResource("5_ev0ch") script = ExtResource("5_ev0ch")
save_dir = "user://resources" save_dir = "user://resources"

View file

@ -1,18 +1,13 @@
extends Node extends Node
#class_name Analitycs class_name Analitycs
var backend := preload("res://resources/backend.tres") @export var backend: BackendSettings
var analytics_senders = [ signal analytics_ready
AnalyticsSenderError.new(),
AnalyticsSenderGate.new(),
AnalyticsSenderApp.new()
]
func _ready() -> void: func _ready() -> void:
await get_user_id() await get_user_id()
for sender in analytics_senders: analytics_ready.emit()
add_child(sender)
func send_event(body: Dictionary = {}) -> void: func send_event(body: Dictionary = {}) -> void:

View file

@ -0,0 +1,13 @@
extends Node
class_name AnalyticsSender
var analytics: Analitycs
func _enter_tree() -> void:
analytics = get_parent()
analytics.analytics_ready.connect(start)
func start() -> void:
pass

View file

@ -1,19 +1,21 @@
extends Node extends AnalyticsSender
class_name AnalyticsSenderApp class_name AnalyticsSenderApp
const HEARTBEAT_DELAY = 60 const HEARTBEAT_DELAY = 60
var heartbeat_timer: Timer var heartbeat_timer: Timer
func _ready() -> void: func start() -> void:
Analytics.send_event(AnalyticsEvents.app_open()) super.start()
analytics.send_event(AnalyticsEvents.app_open())
start_heartbeat() start_heartbeat()
# Send latest exit event # Send latest exit event
var json: String = DataSaver.get_string("analytics", "app_exit") var json: String = DataSaver.get_string("analytics", "app_exit")
if json.is_empty(): return if json.is_empty(): return
DataSaver.set_value("analytics", "app_exit", "") DataSaver.set_value("analytics", "app_exit", "")
Analytics.send_event(JSON.parse_string(json)) analytics.send_event(JSON.parse_string(json))
func start_heartbeat() -> void: func start_heartbeat() -> void:
@ -25,7 +27,7 @@ func start_heartbeat() -> void:
func send_hearbeat() -> void: func send_hearbeat() -> void:
var time_spend = int(Time.get_ticks_msec() / 1000) var time_spend = int(Time.get_ticks_msec() / 1000)
Analytics.send_event(AnalyticsEvents.heartbeat(time_spend)) analytics.send_event(AnalyticsEvents.heartbeat(time_spend))
func _exit_tree() -> void: func _exit_tree() -> void:

View file

@ -1,10 +1,12 @@
extends Node extends AnalyticsSender
class_name AnalyticsSenderError class_name AnalyticsSenderError
func _ready() -> void: func start() -> void:
super.start()
Debug.error.connect(send_error) Debug.error.connect(send_error)
func send_error(msg: String) -> void: func send_error(msg: String) -> void:
Analytics.send_event(AnalyticsEvents.error(msg)) analytics.send_event(AnalyticsEvents.error(msg))

View file

@ -1,13 +1,15 @@
extends Node extends AnalyticsSender
class_name AnalyticsSenderGate class_name AnalyticsSenderGate
var gate_events := preload("res://resources/gate_events.res") @export var gate_events: GateEvents
var gate_open_time: int var gate_open_time: int
var gate_url: String var gate_url: String
func _ready() -> void: func start() -> void:
super.start()
gate_events.search_pressed.connect(send_search_press) gate_events.search_pressed.connect(send_search_press)
gate_events.open_gate.connect(send_gate_open) gate_events.open_gate.connect(send_gate_open)
gate_events.gate_entered.connect(send_gate_enter) gate_events.gate_entered.connect(send_gate_enter)
@ -17,28 +19,28 @@ func _ready() -> void:
var json: String = DataSaver.get_string("analytics", "send_gate_exit") var json: String = DataSaver.get_string("analytics", "send_gate_exit")
if json.is_empty(): return if json.is_empty(): return
DataSaver.set_value("analytics", "send_gate_exit", "") DataSaver.set_value("analytics", "send_gate_exit", "")
Analytics.send_event(JSON.parse_string(json)) analytics.send_event(JSON.parse_string(json))
func send_search_press(url: String) -> void: func send_search_press(url: String) -> void:
Analytics.send_event(AnalyticsEvents.search_press(url)) analytics.send_event(AnalyticsEvents.search_press(url))
func send_gate_open(url: String) -> void: func send_gate_open(url: String) -> void:
gate_url = url gate_url = url
gate_open_time = int(Time.get_ticks_msec() / 1000) gate_open_time = int(Time.get_ticks_msec() / 1000)
Analytics.send_event(AnalyticsEvents.gate_open(url)) analytics.send_event(AnalyticsEvents.gate_open(url))
func send_gate_enter() -> void: func send_gate_enter() -> void:
var download_time = int(Time.get_ticks_msec() / 1000) - gate_open_time var download_time = int(Time.get_ticks_msec() / 1000) - gate_open_time
gate_open_time = int(Time.get_ticks_msec() / 1000) gate_open_time = int(Time.get_ticks_msec() / 1000)
Analytics.send_event(AnalyticsEvents.gate_enter(gate_url, download_time)) analytics.send_event(AnalyticsEvents.gate_enter(gate_url, download_time))
func send_gate_exit() -> void: func send_gate_exit() -> void:
var time_spend = int(Time.get_ticks_msec() / 1000) - gate_open_time var time_spend = int(Time.get_ticks_msec() / 1000) - gate_open_time
Analytics.send_event(AnalyticsEvents.gate_exit(gate_url, time_spend)) analytics.send_event(AnalyticsEvents.gate_exit(gate_url, time_spend))
gate_url = "" gate_url = ""

View file

@ -7,7 +7,7 @@ extends Node
func _ready() -> void: func _ready() -> void:
gate_events.open_gate.connect(func(_url): switch_scene(world_scene)) gate_events.open_gate.connect(func(_url): switch_scene(world_scene))
gate_events.exit_gate.connect(switch_scene.bind(menu_scene)) gate_events.exit_gate.connect(func(): switch_scene(menu_scene))
$Scenes.add_child(menu_scene.instantiate()) $Scenes.add_child(menu_scene.instantiate())