move to be a general Analytics tool
This commit is contained in:
@ -1 +1 @@
|
||||
export { AnalyticsAccount } from './smartanalytics.classes.analyticsaccount'
|
||||
export { Analytics } from './smartanalytics.classes.analytics'
|
||||
|
37
ts/smartanalytics.classes.analytics.ts
Normal file
37
ts/smartanalytics.classes.analytics.ts
Normal file
@ -0,0 +1,37 @@
|
||||
import * as plugins from './smartanalytics.plugins'
|
||||
|
||||
export class Analytics {
|
||||
project: string
|
||||
appName: string
|
||||
apiEndPoint: string
|
||||
secretKey: string = ''
|
||||
constructor (optionsArg: {
|
||||
projectArg: string
|
||||
appNameArg: string
|
||||
apiEndPointArg: string
|
||||
secretKeyArg?: string
|
||||
}) {
|
||||
this.project = optionsArg.projectArg
|
||||
this.appName = optionsArg.appNameArg
|
||||
this.apiEndPoint = optionsArg.apiEndPointArg
|
||||
if (optionsArg.secretKeyArg) {
|
||||
this.secretKey = optionsArg.secretKeyArg
|
||||
}
|
||||
}
|
||||
|
||||
async recordEvent (identifierArg: string, analyticsDataArg: any) {
|
||||
let dataToSend = {
|
||||
project: this.project,
|
||||
appName: this.appName,
|
||||
identifier: identifierArg,
|
||||
analyticsData: analyticsDataArg
|
||||
}
|
||||
let dataToSendJson = JSON.stringify(dataToSend)
|
||||
await plugins.smartrequest.post(this.apiEndPoint, {
|
||||
headers: {
|
||||
'authenticate': this.secretKey
|
||||
},
|
||||
requestBody: dataToSendJson
|
||||
})
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
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)
|
||||
}
|
||||
}
|
@ -5,4 +5,4 @@ import * as smartq from 'smartq'
|
||||
export {
|
||||
smartrequest,
|
||||
smartq
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +0,0 @@
|
||||
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}` + // event category
|
||||
`&ea=${eventActionArg}` + // event action
|
||||
`&el=${eventLabelArg}` + // event label
|
||||
'&ev=300' +
|
||||
`&an=${appNameArg}`
|
||||
send(payload)
|
||||
}
|
||||
|
||||
|
||||
let send = async (requestBodyArg: string) => {
|
||||
await plugins.smartrequest.post('https://www.google-analytics.com/collect', {
|
||||
requestBody: requestBodyArg
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user