一种可能的方法是根据引荐来源实现您自己的算法,但在某些情况下您必须考虑这些情况。乍一看,这里有一些。
- 如何确定唯一点击? (IP、浏览器数据或两者的组合?)
- 引荐来源网址是否唯一? (https://www.facebook.com/, https://m.facebook.com/)
我敢肯定还有其他陷阱。
但是您可以尝试一些跟踪 URL 库,例如 Google Analytics(用于高级统计)或 Google Short URL 用于基本统计。
Stack Overflow 上已经回答了,how to get page view information for specific URLs in Google Analytics。
为您的网址生成一个较短的网址:
curl https://www.googleapis.com/urlshortener/v1/url \
-H 'Content-Type: application/json' \
-d '{"longUrl": "http://www.google.com/"}'
如果生成成功,你会收到如下响应:
{
"kind": "urlshortener#url",
"id": "http://shortenurl/",
"longUrl": "http://www.google.com/"
}
请注意,id 键是您的缩短网址。所以你可以将它存储在你的数据库中。
稍后您可以通过以下调用获取您的缩短网址统计信息:
curl 'https://www.googleapis.com/urlshortener/v1/url?shortUrl=http://shortenurl/fbsS&projection=FULL'
以下是统计数据:
{
"kind": "urlshortener#url",
"id": "http://shortenurl/",
"longUrl": "http://www.google.com/",
"status": "OK",
"created": "2009-12-13T07:22:55.000+00:00",
"analytics": {
"allTime": {
"shortUrlClicks": "3227",
"longUrlClicks": "9358",
"referrers": [ { "count": "2160", "id": "Unknown/empty" } /* , ... */ ],
"countries": [ { "count": "1022", "id": "US" } /* , ... */ ],
"browsers": [ { "count": "1025", "id": "Firefox" } /* , ... */ ],
"platforms": [ { "count": "2278", "id": "Windows" } /* , ... */ ]
},
"month": { /* ... */ },
"week": { /* ... */ },
"day": { /* ... */ },
"twoHours": { /* ... */ }
}
}