added readme and first working version
This commit is contained in:
1
ts/index.ts
Executable file
1
ts/index.ts
Executable file
@ -0,0 +1 @@
|
||||
export { AnalyticsAccount } from './smartanalytics.classes.analyticsaccount'
|
15
ts/smartanalytics.classes.analyticsaccount.ts
Normal file
15
ts/smartanalytics.classes.analyticsaccount.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import * as plugins from './smartanalytics.plugins'
|
||||
import * as send from './smartanalytics.send'
|
||||
|
||||
export class AnalyticsAccount {
|
||||
appName: string
|
||||
trackingId: string
|
||||
constructor(appNameArg: string, trackingIdArg: string) {
|
||||
this.appName = appNameArg
|
||||
this.trackingId = trackingIdArg
|
||||
}
|
||||
|
||||
sendEvent (eventCategoryArg, eventActionArg, eventLabelArg: string) {
|
||||
send.event(this.trackingId, this.appName, eventCategoryArg, eventActionArg, eventLabelArg)
|
||||
}
|
||||
}
|
8
ts/smartanalytics.plugins.ts
Executable file
8
ts/smartanalytics.plugins.ts
Executable file
@ -0,0 +1,8 @@
|
||||
import 'typings-global'
|
||||
import * as smartrequest from 'smartrequest'
|
||||
import * as smartq from 'smartq'
|
||||
|
||||
export {
|
||||
smartrequest,
|
||||
smartq
|
||||
}
|
22
ts/smartanalytics.send.ts
Executable file
22
ts/smartanalytics.send.ts
Executable file
@ -0,0 +1,22 @@
|
||||
import * as plugins from './smartanalytics.plugins'
|
||||
|
||||
export let event = (trackingIdArg: string, appNameArg: string, eventCategoryArg: string, eventActionArg, eventLabelArg: string = 'null') => {
|
||||
let payload: string = 'v=1' +
|
||||
`&tid=${trackingIdArg}` + // the tracking ID
|
||||
'&cid=555' +
|
||||
'&aip=1' + // anonymize the IP
|
||||
'&t=event' +
|
||||
`&ec=${eventCategoryArg}` +
|
||||
`&ea=${eventActionArg}` +
|
||||
`&el=${eventLabelArg}` +
|
||||
'&ev=300' +
|
||||
`&an=${eventLabelArg}`
|
||||
send(payload)
|
||||
}
|
||||
|
||||
|
||||
let send = async (requestBodyArg: string) => {
|
||||
await plugins.smartrequest.post('http://www.google-analytics.com/collect', {
|
||||
requestBody: requestBodyArg
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user