Created
November 18, 2020 15:56
-
-
Save josephcc/6b93a0d68fb15e1eae4c98e14004afec to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { BigQuery } from '@google-cloud/bigquery' | |
import * as functions from 'firebase-functions' | |
import { LoggerRow } from 'bentowidgets/utils/loggerHOC' | |
const bigquery = new BigQuery({ | |
projectId: process.env.GCLOUD_PROJECT, | |
keyFilename: `./service_keys/${process.env.GCLOUD_PROJECT}-service.json` | |
}) | |
export const logSidebarEvent = functions.https.onCall( | |
async (data: LoggerRow, context): Promise<any> => { | |
const user = context.auth ? context.auth.uid : 'unknown' | |
const tableTemplate = bigquery.dataset('fuse_analytics').table('sidebar_logs') | |
return tableTemplate | |
.insert( | |
{ | |
...data, | |
event_time: BigQuery.timestamp(new Date()), | |
user | |
}, | |
{ ignoreUnknownValues: true } | |
) | |
.catch( | |
(err: Error): Error => { | |
console.error(JSON.stringify(err)) | |
return err | |
} | |
) | |
.then((): null => null) | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment