Skip to content

Commit

Permalink
Set HTTP method
Browse files Browse the repository at this point in the history
  • Loading branch information
joe223 committed Aug 14, 2018
1 parent 151406e commit b7ffec0
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 34 deletions.
4 changes: 2 additions & 2 deletions dist/anka-tracker.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/anka-tracker.min.js.map

Large diffs are not rendered by default.

14 changes: 3 additions & 11 deletions src/core/Initializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Sender } from './Sender'

const DEFAULT_CONFIG: InilialzeConfig = {
debug: true,
httpMethod: 'POST',
retry: 2,
interval: 1000,
groupMaxLength: 5,
Expand All @@ -14,6 +15,7 @@ const DEFAULT_CONFIG: InilialzeConfig = {

export class Initializer implements InilialzeConfig {
readonly debug: boolean
readonly httpMethod: string
readonly trackerHost: string
readonly retry: number
readonly interval: number
Expand All @@ -25,16 +27,6 @@ export class Initializer implements InilialzeConfig {
readonly extractOnLaunchOption: boolean

constructor (config: InilialzeConfig = {}) {
config = Object.assign(DEFAULT_CONFIG, config)
this.debug = config.debug
this.trackerHost = config.trackerHost
this.retry = config.retry
this.interval = config.interval
this.commonData = config.commonData
this.groupMaxLength = config.groupMaxLength
this.timestampKey = config.timestampKey
this.queueMaxLength = config.queueMaxLength
this.attachActionToUrl = config.attachActionToUrl
this.extractOnLaunchOption = config.extractOnLaunchOption
Object.assign(this, DEFAULT_CONFIG, config)
}
}
3 changes: 3 additions & 0 deletions src/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ declare interface InilialzeConfig {
// 开启 log 调试
debug?: boolean,

// sender 发送请求是使用的 HTTP 方法
httpMethod?: string,

// 数据接收接口
trackerHost?: string,

Expand Down
2 changes: 1 addition & 1 deletion src/wechat/CommonDataVendor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class WeChatCommonDataVender extends CommonDataVendor {
app_category: '',
source: onLaunchOption.scene,
source_path: onLaunchOption.path,
source_app_id: onLaunchOption.referrerInfo ? onLaunchOption.referrerInfo.appId : '',
source_app_id: onLaunchOption.referrerInfo ? onLaunchOption.referrerInfo.appId || '' : '',
source_params: query,
source_src_key: onLaunchOption.query ? onLaunchOption.query.src || '' : '',
// 业务相关
Expand Down
4 changes: 2 additions & 2 deletions src/wechat/Sender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ export class WeChatSender implements Sender {
}

send (task: Task): Promise<Task> {
let url = this.url
const data = <TrackData>{
...this.commonData,
...task.data
}
let url = this.url
if (this.config.attachActionToUrl) {
const trackAction = data.action || ''
url = /\/$/.test(this.url) ? `${this.url}${trackAction}` : `${this.url}/${trackAction}`
Expand All @@ -30,7 +30,7 @@ export class WeChatSender implements Sender {

return wechat.request({
url,
method: 'POST',
method: this.config.httpMethod,
data
}).then(() => {
// 这一步肥肠重要,只需改变状态即可
Expand Down
5 changes: 3 additions & 2 deletions test/anka-tracker.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
module.exports = {
debug: true,
httpMethod: 'POST',
trackerHost: 'http://bi.baixing.com:9001/dw-web/log',
retry: 1, // 失败重试次数
retry: 0, // 失败重试次数
interval: 2012, // 每组请求发送时间间隔 ms
groupMaxLength: 2, // 每组包含打点数
timestampKey: 'timestamp_ms', // 时间戳 key
Expand All @@ -10,7 +11,7 @@ module.exports = {
commonData: {
__debug: 1, // 默认值是 1
event_type: 'bx_wxmini',
tracktype: 'event', // event 或pageview
tracktype: 'event', // event 或pageview
app_type: 'wx',
app_id: 'wxfd853a0b03d0aea9',
app_name: '宠咖秀',
Expand Down
19 changes: 5 additions & 14 deletions test/anka-tracker.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/anka-tracker.js.map

Large diffs are not rendered by default.

0 comments on commit b7ffec0

Please sign in to comment.