mirror of
https://github.com/thegatesbrowser/thegates.git
synced 2025-08-23 08:17:34 -04:00
analytics initial
This commit is contained in:
parent
94fd2ec903
commit
50c017c567
3 changed files with 35 additions and 0 deletions
7
project/the_gates/resources/backend_settings.tres
Normal file
7
project/the_gates/resources/backend_settings.tres
Normal file
|
@ -0,0 +1,7 @@
|
|||
[gd_resource type="Resource" script_class="BackendSettings" load_steps=2 format=3 uid="uid://cjcdum6fm4ta0"]
|
||||
|
||||
[ext_resource type="Script" path="res://the_gates/scripts/analytics/backend_settings.gd" id="1_8fkk2"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_8fkk2")
|
||||
url = "http://95.163.241.188:8000/"
|
24
project/the_gates/scripts/analytics/analytics.gd
Normal file
24
project/the_gates/scripts/analytics/analytics.gd
Normal file
|
@ -0,0 +1,24 @@
|
|||
extends Node
|
||||
#class_name Analitycs
|
||||
|
||||
var backend_settings = preload("res://the_gates/resources/backend_settings.tres")
|
||||
var handle = "api/analytics"
|
||||
|
||||
func _ready() -> void:
|
||||
send_event("application_enter")
|
||||
|
||||
|
||||
func send_event(name: String, body: Variant = null) -> void:
|
||||
var url = backend_settings.url + handle
|
||||
var data = JSON.stringify(body)
|
||||
|
||||
var http = HTTPRequest.new()
|
||||
http.use_threads = true
|
||||
add_child(http)
|
||||
|
||||
var err = http.request(url, [], HTTPClient.METHOD_POST, data)
|
||||
await http.request_completed
|
||||
remove_child(http)
|
||||
|
||||
if err != HTTPRequest.RESULT_SUCCESS:
|
||||
Debug.logerr("Analitycs event is not sent. Name: " + name)
|
4
project/the_gates/scripts/analytics/backend_settings.gd
Normal file
4
project/the_gates/scripts/analytics/backend_settings.gd
Normal file
|
@ -0,0 +1,4 @@
|
|||
extends Resource
|
||||
class_name BackendSettings
|
||||
|
||||
@export var url: String
|
Loading…
Add table
Add a link
Reference in a new issue