Created
March 4, 2021 08:56
-
-
Save sahava/ba72e713b68e0804de09a11ecf4936f8 to your computer and use it in GitHub Desktop.
Event Data To BigQuery - DEMO of the BigQuery API
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
___INFO___ | |
{ | |
"type": "TAG", | |
"id": "cvt_temp_public_id", | |
"version": 1, | |
"securityGroups": [], | |
"displayName": "Event data to BigQuery", | |
"brand": { | |
"id": "brand_dummy", | |
"displayName": "" | |
}, | |
"description": "", | |
"containerContexts": [ | |
"SERVER" | |
] | |
} | |
___TEMPLATE_PARAMETERS___ | |
[ | |
{ | |
"type": "TEXT", | |
"name": "projectId", | |
"displayName": "Project ID", | |
"simpleValueType": true | |
}, | |
{ | |
"type": "TEXT", | |
"name": "datasetId", | |
"displayName": "Dataset ID", | |
"simpleValueType": true | |
}, | |
{ | |
"type": "TEXT", | |
"name": "tableId", | |
"displayName": "Table ID", | |
"simpleValueType": true | |
} | |
] | |
___SANDBOXED_JS_FOR_SERVER___ | |
const BigQuery = require('BigQuery'); | |
const getAllEventData = require('getAllEventData'); | |
const getRequestHeader = require('getRequestHeader'); | |
const getTimestampMillis = require('getTimestampMillis'); | |
const Math = require('Math'); | |
const eventData = getAllEventData(); | |
const now = Math.round(getTimestampMillis() / 1000); | |
const bigQueryObject = { | |
event_name: eventData.event_name, | |
event_date: now, | |
page_location: eventData.page_location, | |
event_parameters: [{ | |
key: 'geolocation_city', | |
value: getRequestHeader('X-Appengine-City') | |
},{ | |
key: 'geolocation_country', | |
value: getRequestHeader('X-Appengine-Country') | |
}], | |
user_ip: eventData.ip_override, | |
user_agent: eventData.user_agent, | |
user_id: eventData.client_id | |
}; | |
BigQuery.insert({ | |
projectId: data.projectId, | |
datasetId: data.datasetId, | |
tableId: data.tableId | |
}, [bigQueryObject], {}, data.gtmOnSuccess, data.gtmOnFailure); | |
___SERVER_PERMISSIONS___ | |
[ | |
{ | |
"instance": { | |
"key": { | |
"publicId": "read_request", | |
"versionId": "1" | |
}, | |
"param": [ | |
{ | |
"key": "requestAccess", | |
"value": { | |
"type": 1, | |
"string": "any" | |
} | |
}, | |
{ | |
"key": "headerAccess", | |
"value": { | |
"type": 1, | |
"string": "any" | |
} | |
}, | |
{ | |
"key": "queryParameterAccess", | |
"value": { | |
"type": 1, | |
"string": "any" | |
} | |
} | |
] | |
}, | |
"clientAnnotations": { | |
"isEditedByUser": true | |
}, | |
"isRequired": true | |
}, | |
{ | |
"instance": { | |
"key": { | |
"publicId": "read_event_data", | |
"versionId": "1" | |
}, | |
"param": [ | |
{ | |
"key": "eventDataAccess", | |
"value": { | |
"type": 1, | |
"string": "any" | |
} | |
} | |
] | |
}, | |
"clientAnnotations": { | |
"isEditedByUser": true | |
}, | |
"isRequired": true | |
}, | |
{ | |
"instance": { | |
"key": { | |
"publicId": "access_bigquery", | |
"versionId": "1" | |
}, | |
"param": [ | |
{ | |
"key": "allowedTables", | |
"value": { | |
"type": 2, | |
"listItem": [ | |
{ | |
"type": 3, | |
"mapKey": [ | |
{ | |
"type": 1, | |
"string": "projectId" | |
}, | |
{ | |
"type": 1, | |
"string": "datasetId" | |
}, | |
{ | |
"type": 1, | |
"string": "tableId" | |
}, | |
{ | |
"type": 1, | |
"string": "operation" | |
} | |
], | |
"mapValue": [ | |
{ | |
"type": 1, | |
"string": "*" | |
}, | |
{ | |
"type": 1, | |
"string": "*" | |
}, | |
{ | |
"type": 1, | |
"string": "*" | |
}, | |
{ | |
"type": 1, | |
"string": "write" | |
} | |
] | |
} | |
] | |
} | |
} | |
] | |
}, | |
"clientAnnotations": { | |
"isEditedByUser": true | |
}, | |
"isRequired": true | |
} | |
] | |
___TESTS___ | |
scenarios: [] | |
___NOTES___ | |
Created on 04/03/2021, 10:54:54 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment