Skip to content

Commit

Permalink
[#] GA4 修复无用户计数的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
huiyadanli committed Apr 17, 2023
1 parent c503d8c commit e3dc309
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions RevokeMsgPatcher/Utils/GAHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static GAHelper Instance

public GAHelper()
{
UserAgent = string.Format("Hui Google Analytics Tracker/1.0 ({0}; {1}; {2})", Environment.OSVersion.Platform.ToString(), Environment.OSVersion.Version.ToString(), Environment.OSVersion.VersionString);
UserAgent = $"Hui Google Analytics Tracker/1.0 ({Environment.OSVersion.Platform.ToString()}; {Environment.OSVersion.Version.ToString()}; {Environment.OSVersion.VersionString})";
}

public async Task RequestPageViewAsync(string page, string title = null)
Expand All @@ -68,20 +68,27 @@ public async Task RequestPageViewAsync(string page, string title = null)
{ "client_id",UserAgent},
{ "user_id", cid },
{ "non_personalized_ads", "false" },
{ "events", new List<Dictionary<string, string>>()
{ "events", new List<Dictionary<string, object>>()
{
new Dictionary<string, string>()
new Dictionary<string, object>()
{
{ "name",page},
{ "name",page },
{
"params",
new Dictionary<string, object>()
{
{ "engagement_time_msec", "1"},
}
},
}
}
},
};
JavaScriptSerializer serializer = new JavaScriptSerializer();
string json = serializer.Serialize(values);
var serializer = new JavaScriptSerializer();
var json = serializer.Serialize(values);
var content = new StringContent(json, Encoding.UTF8, "application/json");
var response = await client.PostAsync(GAUrl, content);
Console.WriteLine(response.ToString());
// Console.WriteLine(response.ToString());
}
catch (Exception ex)
{
Expand Down

0 comments on commit e3dc309

Please sign in to comment.