Skip to content

Instantly share code, notes, and snippets.

CREATE TABLE ID_GRAPH_0 (
orig_anon_id varchar(32),
orig_user_id varchar(32),
curr_anon_id varchar(32),
curr_user_id varchar(32),
version_anon_id int,
version_user_id int,
);
CREATE TABLE ID_GRAPH_0 (
orig_anon_id varchar(32),
orig_user_id varchar(32),
curr_anon_id varchar(32),
curr_user_id varchar(32),
version_anon_id int,
version_user_id int,
);
{
"cloudwatch.emitMetrics": true,
"kinesis.endpoint": "",
"firehose.endpoint": "",
"flows": [
{
"filePattern": "/tmp/*.csv",
"kinesisStream": "lambda-integration-poc",
"partitionKeyOption": "RANDOM",
testuser1,0001,0001,sample product 1,001,51.00
testuser1,0001,0002,sample product 2,002,23.50
{ "anonymousId": "testuser1", "orderId": "0001", "itemId": "0001", "itemName": "sample product 1",
"qty": "001", "unitPrice": "51.00" }
{ "anonymousId": "testuser1", "orderId": "0001", "itemId": "0002", "itemName": "sample product 2",
"qty": "002", "unitPrice": "23.50" }
'use strict';
const Analytics = require("@rudderstack/rudder-sdk-node");
//
//
module.exports.helloWorld = (event, context, callback) => {
const response = {
statusCode: 200,
headers: {
'Access-Control-Allow-Origin': '*', // Required for CORS support to work
{"type": "track", "event": "Order Completed", "sentAt": "2020-04-15T09:59:50.246Z", "context": {"library": {"name": "analytics-node", "version": "0.0.1"}}, "_metadata": {"nodeVersion": "12.16.1"}, "messageId": "node-5306d64b863bdf7c95cce1442c70f3ac-1345b9b5-c5a9-4c1b-8338-64762ff2de8d", "timestamp": "2020-04-15T09:59:50.27Z", "properties": {"order": {"revenue": 98, "order_id": "0001", "products": [{"name": "sample product 1", "product_id": "0001"}, {"name": "sample product 2", "product_id": "0002"}]}}, "receivedAt": "2020-04-15T09:59:50.271Z", "request_ip": "34.205.171.63:54764", "anonymousId": "testuser1", "originalTimestamp": "2020-04-15T09:59:50.245Z"}
function transform(events) {
const filterEventNames = [
// Add list of event names that you want to filter out
"game_load_time",
"lobby_fps"
];
//remove events whose name match those in above list
const filteredEvents = events.filter(event => {
const eventName = event.event;
//remove events of a certain type if related property value does not satisfy the pre-defined condition
//in this example, if 'total_payment' for a 'spin' event is null or 0, then it would be removed.
//Only non-null, non-zero 'spin' events would be considered
const nonSpinAndSpinPayerEvents = filteredEvents.filter( event => {
const eventName = event.event;
// spin events
if(eventName.toLowerCase().indexOf('spin') >= 0) {
if(event.userProperties && event.userProperties.total_payments
&& event.userProperties.total_payments > 0) {
return true;
//in the below example, aggregation of three attributes - 'bet_amount', 'win_amount' and 'no_of_spin'
//for all 'spin_result' events in the batch is being performed and instead of N 'spin_result' events,
//a single 'spin_result' event with cumulative values is being provided
let spin_result_events = nonSpinAndSpinPayerEvents.filter(event => {
return event.event == "spin_result";
});
let bet_amount = 0;
let win_amount = 0;
let no_of_spin = 0;
<pre><code class="language-json">"event_payload": {
"batch": {
"channel": "mobile",
"sentAt": "2019-12-10T09:35:34.763Z",
"messageId": "1575970534464-bfe73f1a-0186-4fd8-ac1d-109e109b0fb4",
"event": "hyper_bonus_purchase",
"anonymousId": "27612234ca5b2",
"type": "track",
"properties": {
"ishighroller": "False",