我实现了AMP页面,他们没有错误的索引,并出现在谷歌搜索。当访问者点击Google上的链接时,他们就会出现在Google (包括缓存的页面)上,并从organic/google中引用。但是,当访问者单击AMP页面上的链接时,有时会期望引用者是referral/ampprogect.org,在很多情况下是direct/none。
当然,amp-analytics已经设置好了。
我怀疑,当AMP页面响应缓存页面的单击而从主服务器服务时,就会出现direct/none。
以防万一,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-analitics块
<amp-analytics config="https://www.googletagmanager.com/amp.json?id=GTM-zzzzzz>m.url=SOURCE_URL" data-credentials="include"></amp-analytics>结果是一样的。
从缓存的 AMP页面(即https://google.com/mydomain-com.cdn...)到non的单击显示referral/ampproject.org,单击非缓存的AMP (即https : //mydomain.com/amp/something.aspx)显示direct/none。
发布于 2017-10-06 00:57:12
多亏了这个伟大的职位,我才知道出了什么问题,并将这些想法应用到了.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>m.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>m.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>m.url=SOURCE_URL" data-credentials="include"></amp-analytics>现在,所有来自缓存和非缓存AMP页面的点击都显示了organic/google。
https://stackoverflow.com/questions/46509133
复制相似问题