gpt4 book ai didi

google-analytics - Google Analytics(分析)将来自缓存功放页面的点击显示为直接/无

转载 作者:行者123 更新时间:2023-12-03 16:47:28 26 4
gpt4 key购买 nike

我实施了AMP页面,它们被正确索引,并出现在Google搜索中。当访问者单击Google SERP上的链接时,他们会出现在organic/google引用的Google Analytics(分析)中(包括缓存的页面)。但是,当访问者单击该AMP页面上的链接时,有时会期望引荐来源网址为referral/ampprogect.org,在许多情况下为direct/none
当然,已设置amp-analytics
我怀疑当响应来自缓存页面的点击而从主服务器提供AMP页面时,出现direct/none
以防万一,AMP是几天前发布的,到目前为止还没有被全部发现。
有什么意义吗?
Amp分析以非常基本的方式实现

<amp-analytics type="googleanalytics">
<script type="application/json">
{
"vars": {
"account": "UA-XXXXX-Y" //real account id for sure
},
"triggers": {
"trackPageview": {
"on": "visible",
"request": "pageview"
}
}
}
</script>
</amp-analytics>


更新资料

我为AMP设置了Google跟踪代码管理器,并使用

<amp-analytics config="https://www.googletagmanager.com/amp.json?id=GTM-zzzzzz&gtm.url=SOURCE_URL" data-credentials="include"></amp-analytics>


结果相同。
从缓存的 amp-analitics页面(即 AMP)到非放大器的单击显示为 https://google.com/mydomain-com.cdn...,单击非缓存的AMP(即 referral/ampproject.org)显示为 https : //mydomain.com/amp/something.aspx

最佳答案

多亏了this great post,我才明白出了什么问题,并将这些想法应用于了.NET。主要思想是捕获amp-analytics配置对象(JSON格式)并将其替换为我自己的(内部带有clientId)。
首先,我创建了HttpHandler

''//.VB
Namespace AmpHandlers
Public Class AmpConfig
Implements IHttpHandler

Private Const unixStart As DateTime = #1/1/1970# ''//start of epoc

Public ReadOnly Property IsReusable As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property

Public Sub ProcessRequest(context As HttpContext) Implements IHttpHandler.ProcessRequest
context.Response.Clear()
''//ecpected request
''// https : //mydomain.com/gtm-amp.json?id=GTM-zzzzzz&gtm.url=SOURCE_URL
If String.IsNullOrEmpty(context.Request.QueryString("id")) OrElse context.Request.QueryString("id") <> "GTM-zzzzzz" Then
''//no answer
context.Response.End()
Return
End If
Dim clientId As String = ""
If context.Request.Cookies("_ga") IsNot Nothing Then
Dim ga As String = context.Request.Cookies("_ga").Value ''//GA1.2.12321354.1507250223
clientId = Regex.Match(ga, "(\d+?\.\d+?$)").Groups(1).Value
Else
Dim rand As New Random()
''//Majic 2147483647 is upper limit of Google's random part of _ga cookie
''//The second part is Unix time, in seconds
clientId = rand.Next(2147483647) & "." & CInt(DateTime.UtcNow.Subtract(unixStart).TotalSeconds)
End If
''//Set cookie and response headers
context.Response.ContentType = "application/json" '; charset=UTF-8
context.Response.SetCookie(New HttpCookie("_ga") With {.Value = "GA1.2." & clientId,
.Path = "/", .Domain = context.Request.Url.Host, .Expires = DateTime.UtcNow.AddYears(2)
})
context.Response.AddHeader("Access-Control-Allow-Origin", "https://mydomain-com.cdn.ampproject.org")
context.Response.AddHeader("Access-Control-Expose-Headers", "AMP-Access-Control-Allow-Source-Origin")
context.Response.AddHeader("AMP-Access-Control-Allow-Source-Origin", "https://" & context.Request.Url.Host)
context.Response.AddHeader("Access-Control-Allow-Source-Origin", "https://" & context.Request.Url.Host)
context.Response.AddHeader("Access-Control-Allow-Credentials", "true")
context.Response.AddHeader("Content-Disposition", "attachment; filename=""GTM-NZPM27T.json""")
context.Response.AddHeader("cache-control", "no-cache, no-store, must-revalidate")

''//https://www.googletagmanager.com/amp.json?id=GTM-zzzzzz&gtm.url=SOURCE_URL response is saved locally and edited
''//possibly it is not the best colution
Dim sr As New IO.StreamReader(context.Server.MapPath("~/amp-gtm.config"))
Dim str As String = sr.ReadToEnd()
str = str.Replace("[[clientId]]", clientId)
context.Response.Write(str)
context.Response.Flush()
context.Response.End()
End Sub
End Class
End Namespace


接下来,我在 web.config中注册了它。

<handlers>
<add name="amp-gtm" verb="GET" path="gtm-amp.json" type="AmpHandlers.AmpConfig" resourceType="Unspecified"/>
</handlers>


最后放入 amp-analytics标记。

<amp-analytics config="https : //mydomain.com/gtm-amp.json?id=GTM-zzzzzz&gtm.url=SOURCE_URL" data-credentials="include"></amp-analytics>


现在,来自缓存和非缓存AMP页面的所有点击均显示 organic/google

关于google-analytics - Google Analytics(分析)将来自缓存功放页面的点击显示为直接/无,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46509133/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com