Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
littlewin
committed
Nov 29, 2017
1 parent
f17b6ee
commit 976f1a5
Showing
3 changed files
with
38 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* @file Google Analytics控制 | ||
* @author littlewin(littlewin.wang@gmail.com) | ||
*/ | ||
|
||
const request = require('request') | ||
const config = require('config/env')[process.env.NODE_ENV || 'development'] | ||
|
||
class GA { | ||
static async post (ctx) { | ||
let { query } = ctx.request.body | ||
|
||
if (!query) { | ||
ctx.throw(404, "谷歌分析提交参数为空") | ||
} | ||
|
||
const ip = (ctx.header['x-forwarded-for'] || ctx.header['x-real-ip'] || ctx.ip || ctx.ips[0]) | ||
|
||
query += `&dh=${config.INFO.site}&tid=${config.INFO.GA}&uip=${ip}` | ||
|
||
ctx.status = 200, | ||
ctx.body = { | ||
success: true, | ||
message: "谷歌分析已提交" | ||
} | ||
|
||
request.get({ | ||
url: `https://www.google-analytics.com/collect${query}`, | ||
}) | ||
} | ||
} | ||
|
||
module.exports = GA |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters