smartanalytics/ts/smartanalytics.classes.analytics.ts

40 lines
1012 B
TypeScript
Raw Permalink 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-23 23:06:09 +00:00
projectIdArg: string
2017-08-23 12:55:11 +00:00
appNameArg: string
apiEndPointArg: string
secretKeyArg?: string
}) {
2017-08-23 23:06:09 +00:00
this.projectId = optionsArg.projectIdArg
2017-08-23 12:55:11 +00:00
this.appName = optionsArg.appNameArg
this.apiEndPoint = optionsArg.apiEndPointArg
if (optionsArg.secretKeyArg) {
this.secretKey = optionsArg.secretKeyArg
}
}
async recordEvent (identifierArg: string, analyticsDataArg: any) {
let dataToSend = {
2017-08-23 23:06:09 +00:00
projectId: this.projectId,
2017-08-23 12:55:11 +00:00
appName: this.appName,
identifier: identifierArg,
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
})
}
}