-
Notifications
You must be signed in to change notification settings - Fork 5
Feature - add analytics #44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
edge-marge
wants to merge
11
commits into
main
Choose a base branch
from
feature/analytics
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
814cd9a
add analytics
edge-marge 65d89fc
refactor analytics code
edge-marge 60146f6
Merge branch 'main' into feature/analytics
edge-marge d6ae676
update analytics integration;
edge-marge 1b5933f
use metadata default tag
edge-marge 4e55ff5
2nd round review
edge-marge 21574de
missing meta
edge-marge 94ca54f
missing conditional check
edge-marge 25de479
url fix
edge-marge 4ffbc17
add docker validation check
edge-marge 8d11dea
edit docker analytics
edge-marge File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Net.Http; | ||
| using System.Net.Http.Headers; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
| using Newtonsoft.Json; | ||
| using UnityEngine; | ||
|
|
||
| namespace Edgegap.Editor.Api | ||
| { | ||
| public class AnalyticsApi | ||
| { | ||
| private readonly HttpClient _httpClient = new HttpClient(); | ||
| private string _url = "https://r.edgegap.net/"; | ||
| private string _Key = "phc_sjDOXB5OakYZu0h70u4GLcFR7hZ55XfnnDef5xaeDws"; | ||
| private string _Event = "Plugin Button Click"; | ||
|
|
||
| private class AnalyticsPayload | ||
| { | ||
| [JsonProperty("api_key")] | ||
| public string ApiKey { get; set; } | ||
|
|
||
| [JsonProperty("event")] | ||
| public string Event { get; set; } | ||
|
|
||
| [JsonProperty("distinct_id")] | ||
| public string DistinctId { get; set; } | ||
|
|
||
| [JsonProperty("properties")] | ||
| public Dictionary<string, string> Properties { get; set; } | ||
|
|
||
| public AnalyticsPayload( | ||
| string apiKey, | ||
| string ev, | ||
| string disctinctId, | ||
| Dictionary<string, string> properties | ||
| ) | ||
| { | ||
| this.ApiKey = apiKey; | ||
| this.Event = ev; | ||
| this.DistinctId = disctinctId; | ||
| this.Properties = properties; | ||
| } | ||
|
|
||
| public override string ToString() => JsonConvert.SerializeObject(this); | ||
| } | ||
|
|
||
| public AnalyticsApi() | ||
| { | ||
| this._httpClient.BaseAddress = new Uri(_url); | ||
| this._httpClient.DefaultRequestHeaders.Accept.Add( | ||
| new MediaTypeWithQualityHeaderValue("application/json") | ||
| ); | ||
| } | ||
|
|
||
| public async Task<HttpResponseMessage> PostAsync( | ||
| string distinctId, | ||
| Dictionary<string, string> properties | ||
| ) | ||
| { | ||
| AnalyticsPayload payload = new AnalyticsPayload(_Key, _Event, distinctId, properties); | ||
| StringContent stringContent = new StringContent( | ||
| payload.ToString(), | ||
| Encoding.UTF8, | ||
| "application/json" | ||
| ); | ||
|
|
||
| try | ||
| { | ||
| return await _httpClient.PostAsync(_httpClient.BaseAddress, stringContent); | ||
| } | ||
| catch (Exception e) | ||
| { | ||
| Debug.LogError($"Error: {e}"); | ||
| throw; | ||
| } | ||
| } | ||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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
19 changes: 19 additions & 0 deletions
19
Editor/Api/Models/Results/GetOrganizationInformationResult.cs
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| using Newtonsoft.Json; | ||
|
|
||
| namespace Edgegap.Editor.Api.Models.Results | ||
| { | ||
| /// <summary> | ||
| /// Result model for `GET /v1/wizard/organization-information`. | ||
| /// </summary> | ||
| public class GetOrganizationInformationResult | ||
| { | ||
| [JsonProperty("distinct_id")] | ||
| public string DistinctId { get; set; } | ||
|
|
||
| [JsonProperty("identifier")] | ||
| public string Identifier { get; set; } | ||
|
|
||
| [JsonProperty("provider")] | ||
| public string Provider { get; set; } | ||
| } | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.