Skip to content

Commit

Permalink
feat: 访问来源统计增加 几种搜索引擎
Browse files Browse the repository at this point in the history
  • Loading branch information
xjq committed Dec 6, 2022
1 parent ee997c5 commit bbadd45
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
6 changes: 6 additions & 0 deletions client/src/utils/codeType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ export enum Channel {
v2ex,
'tools.fun',
github,
google,
baidu,
bing,
}

export const ChannelText = {
Expand All @@ -48,4 +51,7 @@ export const ChannelText = {
[Channel.v2ex]: 'v2ex',
[Channel['tools.fun']]: 'tools.fun',
[Channel.github]: 'Github',
[Channel.google]: 'Google',
[Channel.baidu]: 'Baidu',
[Channel.bing]: 'bing',
};
12 changes: 9 additions & 3 deletions client/src/utils/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,19 @@ export function prettierCodeFormat(code: string) {

export function parseReferrerToChannel() {
const referrer = document.referrer;
if (/juejin/.test(referrer)) {
if (/juejin\.cn/.test(referrer)) {
return Channel.juejin;
} else if (/v2ex/.test(referrer)) {
} else if (/v2ex\.com/.test(referrer)) {
return Channel.v2ex;
} else if (/tools\.fun/.test(referrer)) {
return Channel['tools.fun'];
} else if (/github/.test(referrer)) {
} else if (/github\.com/.test(referrer)) {
return Channel.github;
} else if (/google\.com/.test(referrer)) {
return Channel.google;
} else if (/baidu\.com/.test(referrer)) {
return Channel.baidu;
} else if (/bing\.com/.test(referrer)) {
return Channel.bing;
}
}
2 changes: 1 addition & 1 deletion server/sql/runcode.sql
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ CREATE TABLE `stat` (
`province` varchar(128) NOT NULL DEFAULT '' COMMENT '',
`city` varchar(128) NOT NULL DEFAULT '' COMMENT '城市',
`isp` varchar(128) NOT NULL DEFAULT '' COMMENT '城市运营商',
`channel` int UNSIGNED NOT NULL DEFAULT 0 COMMENT '来源渠道: 0: 自来, 1: v2ex, 2: 掘金, 3: tools.fun',
`channel` int UNSIGNED NOT NULL DEFAULT 0 COMMENT '来源渠道: 0: 自来, 1: v2ex, 2: 掘金, 3: tools.fun 4: github 5: google 6: baidu 7: bing',
`createdAt` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 0 COMMENT = '访问数据' ROW_FORMAT = Dynamic;
Expand Down
6 changes: 6 additions & 0 deletions server/src/utils/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ export enum Channel {
v2ex,
'tools.fun',
github,
google,
baidu,
bing,
}

export const ChannelText = {
Expand All @@ -48,4 +51,7 @@ export const ChannelText = {
[Channel.v2ex]: 'v2ex',
[Channel['tools.fun']]: 'tools.fun',
[Channel.github]: 'Github',
[Channel.google]: 'Google',
[Channel.baidu]: 'Baidu',
[Channel.bing]: 'bing',
};

0 comments on commit bbadd45

Please sign in to comment.