smartanalytics/ts/smartanalytics.classes.analytics.ts

40 lines
976 B
TypeScript
Raw Normal View History

2017-08-23 12:55:11 +00:00
import * as plugins from './smartanalytics.plugins'
export class Analytics {
2017-08-23 23:06:09 +00:00
projectId: string
2017-08-23 12:55:11 +00:00
appName: string
apiEndPoint: string
secretKey: string = ''
constructor (optionsArg: {
2017-08-29 13:18:10 +00:00
projectId: string
appName: string
apiEndPoint: string
secretKey?: string
2017-08-23 12:55:11 +00:00
}) {
2017-08-29 13:18:10 +00:00
this.projectId = optionsArg.projectId
this.appName = optionsArg.appName
this.apiEndPoint = optionsArg.apiEndPoint
if (optionsArg.secretKey) {
this.secretKey = optionsArg.secretKey
2017-08-23 12:55:11 +00:00
}
}
2017-08-29 13:18:10 +00:00
async recordEvent (eventIdArg: string, analyticsDataArg: any) {
2017-08-23 12:55:11 +00:00
let dataToSend = {
2017-08-23 23:06:09 +00:00
projectId: this.projectId,
2017-08-23 12:55:11 +00:00
appName: this.appName,
2017-08-29 13:18:10 +00:00
eventId: eventIdArg,
2017-08-23 12:55:11 +00:00
analyticsData: analyticsDataArg
}
await plugins.smartrequest.post(this.apiEndPoint, {
headers: {
2017-08-23 15:33:30 +00:00
'authenticate': this.secretKey,
'Content-Type': 'application/json'
2017-08-23 12:55:11 +00:00
},
2017-08-23 15:33:30 +00:00
requestBody: dataToSend
}).catch(err => {
console.log(err)
2017-08-23 12:55:11 +00:00
})
}
}