Created
July 28, 2023 04:30
-
-
Save deanpeterson/26a140e6794f61d7247fc4ed17112fb0 to your computer and use it in GitHub Desktop.
login metric
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private IEnumerator SendIdentifyTrackingApiCallCoroutine(UserProfile userProfile) | |
{ | |
Metric metric = Metric.createInstance(Guid.NewGuid().ToString(), "login", null, PlayerPrefs.GetString("session_state"), 0, userProfile); | |
MetricService.Instance.SaveMetric(metric, RequestMethod.POST); | |
string apiUrl = "https://x.skymavis.com/track"; | |
string api_key = "xxxxx"; | |
string authorizationHeader = "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(api_key + ":")); | |
Guid guid = Guid.NewGuid(); | |
var requestBody = new | |
{ | |
api_key = api_key, | |
events = new[] | |
{ | |
new | |
{ | |
type = "identify", | |
data = new | |
{ | |
user_id = userProfile.keycloaksubject, | |
@event = metric.@event, | |
uuid = metric.uuid, | |
@ref = metric.@ref, | |
session_id = metric.session_id, | |
offset = metric.offset, | |
timestamp = metric.timestamp.ToString("yyyy-MM-dd HH:mm:ss"), | |
user_properties = new { | |
email = userProfile.email | |
} | |
}, | |
}, | |
}, | |
}; | |
string json = JsonConvert.SerializeObject(requestBody); | |
HttpWebRequest request = (HttpWebRequest)System.Net.WebRequest.Create(apiUrl); | |
request.Method = "POST"; | |
request.ContentType = "application/json"; | |
request.Headers.Add("Authorization", authorizationHeader); | |
CoroutineWithData cd = new CoroutineWithData(this, SendRequest(request, json)); | |
yield return cd.coroutine; | |
if (cd.result != null) | |
{ | |
Debug.Log($"Identify tracking API call sent successfully: {cd.result}"); | |
userProfile.identified = true; | |
UserProfileService.Instance.UpdateUserProfileIdentified(userProfile); | |
} | |
else | |
{ | |
Debug.LogError("Error sending identify tracking API call"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment