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