From e3dc309502ffe5e9b77f000f9ecbae08f4040330 Mon Sep 17 00:00:00 2001 From: huiyadanli Date: Mon, 17 Apr 2023 22:41:31 +0800 Subject: [PATCH] =?UTF-8?q?[#]=20GA4=20=E4=BF=AE=E5=A4=8D=E6=97=A0?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E8=AE=A1=E6=95=B0=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RevokeMsgPatcher/Utils/GAHelper.cs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/RevokeMsgPatcher/Utils/GAHelper.cs b/RevokeMsgPatcher/Utils/GAHelper.cs index 1de8d42..4608b0a 100644 --- a/RevokeMsgPatcher/Utils/GAHelper.cs +++ b/RevokeMsgPatcher/Utils/GAHelper.cs @@ -50,7 +50,7 @@ namespace RevokeMsgPatcher.Utils 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) @@ -68,20 +68,27 @@ namespace RevokeMsgPatcher.Utils { "client_id",UserAgent}, { "user_id", cid }, { "non_personalized_ads", "false" }, - { "events", new List>() + { "events", new List>() { - new Dictionary() + new Dictionary() { - { "name",page}, + { "name",page }, + { + "params", + new Dictionary() + { + { "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) {