mirror of
https://github.com/eiblog/eiblog.git
synced 2026-02-04 13:52:26 +08:00
更新谷歌统计
This commit is contained in:
@@ -34,6 +34,11 @@ disqus:
|
||||
# 热搜词配置
|
||||
hotwords:
|
||||
- docker
|
||||
# 谷歌统计
|
||||
google:
|
||||
tid: UA-77251712-1
|
||||
v: "1"
|
||||
t: pageview
|
||||
# 运行模式
|
||||
mode:
|
||||
# you can fix certfile, keyfile, domain
|
||||
|
||||
20
front.go
20
front.go
@@ -29,10 +29,9 @@ func Filter() gin.HandlerFunc {
|
||||
|
||||
// 用户识别
|
||||
func UserCookie(c *gin.Context) {
|
||||
cookie, err := c.Request.Cookie("u")
|
||||
if err != nil || cookie.Value == "" {
|
||||
b := []byte(c.ClientIP() + time.Now().String())
|
||||
c.SetCookie("u", fmt.Sprintf("%x", SHA1(b)), 86400*999, "/", "", true, true)
|
||||
cookie, err := c.Cookie("u")
|
||||
if err != nil || cookie == "" {
|
||||
c.SetCookie("u", RandUUIDv4(), 86400*730, "/", "", true, true)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,8 +208,17 @@ func HandleSitemap(c *gin.Context) {
|
||||
func HandleBeacon(c *gin.Context) {
|
||||
ua := c.Request.UserAgent()
|
||||
// TODO 过滤黑名单
|
||||
vals := c.Request.URL.Query()
|
||||
vals.Set("v", setting.Conf.Google.V)
|
||||
vals.Set("tid", setting.Conf.Google.Tid)
|
||||
vals.Set("t", setting.Conf.Google.T)
|
||||
cookie, _ := c.Cookie("u")
|
||||
vals.Set("cid", cookie)
|
||||
|
||||
vals.Set("dl", c.Request.Host+c.Request.RequestURI)
|
||||
vals.Set("uip", c.ClientIP())
|
||||
go func() {
|
||||
req, err := http.NewRequest("POST", "https://www.google-analytics.com/collect", strings.NewReader(c.Request.URL.RawQuery))
|
||||
req, err := http.NewRequest("POST", "https://www.google-analytics.com/collect", strings.NewReader(vals.Encode()))
|
||||
if err != nil {
|
||||
logd.Error(err)
|
||||
return
|
||||
@@ -231,7 +239,7 @@ func HandleBeacon(c *gin.Context) {
|
||||
logd.Error(string(data))
|
||||
}
|
||||
}()
|
||||
c.String(http.StatusAccepted, "accepted")
|
||||
c.String(http.StatusNoContent, "accepted")
|
||||
}
|
||||
|
||||
// 服务端获取评论详细
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"crypto/sha1"
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
"io"
|
||||
@@ -11,6 +10,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/eiblog/utils/logd"
|
||||
"github.com/eiblog/utils/uuid"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -32,8 +32,8 @@ func VerifyPasswd(origin, name, input string) bool {
|
||||
return origin == EncryptPasswd(name, input)
|
||||
}
|
||||
|
||||
func SHA1(data []byte) [sha1.Size]byte {
|
||||
return sha1.Sum(data)
|
||||
func RandUUIDv4() string {
|
||||
return uuid.NewV4().String()
|
||||
}
|
||||
|
||||
func ReadDir(dir string, filter func(name string) bool) (files []string) {
|
||||
|
||||
@@ -43,9 +43,14 @@ type Config struct {
|
||||
Interval int
|
||||
}
|
||||
HotWords []string // 热搜词
|
||||
Mode RunMode // 运行模式
|
||||
Twitter string // twitter地址
|
||||
Blogger struct { // 初始化数据
|
||||
Google struct { // 谷歌统计
|
||||
Tid string
|
||||
V string
|
||||
T string
|
||||
}
|
||||
Mode RunMode // 运行模式
|
||||
Twitter string // twitter地址
|
||||
Blogger struct { // 初始化数据
|
||||
BlogName string
|
||||
SubTitle string
|
||||
BeiAn string
|
||||
|
||||
Reference in New Issue
Block a user