Skip to content

Commit

Permalink
Fix(logging): profile union and set calls to analytics (#3256)
Browse files Browse the repository at this point in the history
* fix(core): logging of connectors and profile identified

* fix(core): remove profile-set from profile-union call in logging

* fix: Incorrect formatting

---------

Co-authored-by: Alan Rynne <[email protected]>
  • Loading branch information
teocomi and AlanRynne authored Apr 5, 2024
1 parent 5fb0342 commit b025200
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
35 changes: 31 additions & 4 deletions Core/Core/Logging/Analytics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,6 @@ internal static void AddConnectorToProfile(string hashedEmail, string connector)
new List<string> { connector }
}
}
},
{
"set",
new Dictionary<string, object> { { "Identified", true } }
}
};
string json = JsonConvert.SerializeObject(data);
Expand All @@ -288,6 +284,37 @@ internal static void AddConnectorToProfile(string hashedEmail, string connector)
});
}

internal static void IdentifyProfile(string hashedEmail, string connector)
{
Task.Run(async () =>
{
try
{
var data = new Dictionary<string, object>
{
{ "$token", MIXPANEL_TOKEN },
{ "$distinct_id", hashedEmail },
{
"$set",
new Dictionary<string, object> { { "Identified", true } }
}
};
string json = JsonConvert.SerializeObject(data);

var query = new StreamContent(new MemoryStream(Encoding.UTF8.GetBytes("data=" + HttpUtility.UrlEncode(json))));
using HttpClient client = Http.GetHttpProxyClient();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/plain"));
query.Headers.ContentType = new MediaTypeHeaderValue("application/json");
var res = await client.PostAsync(MIXPANEL_SERVER + "/engage#profile-set", query).ConfigureAwait(false);
res.EnsureSuccessStatusCode();
}
catch (Exception ex) when (!ex.IsFatal())
{
SpeckleLog.Logger.ForContext("connector", connector).Warning(ex, "Failed identify profile");
}
});
}

private static string GetOs()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
Expand Down
1 change: 1 addition & 0 deletions Core/Core/Logging/Setup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public static void Init(
foreach (var account in AccountManager.GetAccounts())
{
Analytics.AddConnectorToProfile(account.GetHashedEmail(), hostApplication);
Analytics.IdentifyProfile(account.GetHashedEmail(), hostApplication);
}
}

Expand Down

0 comments on commit b025200

Please sign in to comment.