This file contains 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
{ | |
"anonymousId": "a5b62615-cf5e-4e1c-bd01-a9852914baaa", | |
"context": { | |
"campaign": { | |
"medium": "ppc", | |
"name": "High Intent Keywords", | |
"source": "adwords", | |
"term": "" | |
}, | |
"ip": "8.8.8.8", |
This file contains 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
const AWS = require('aws-sdk'); | |
const { DocumentClient } = require('aws-sdk/clients/dynamodb'); | |
module.exports = () => { | |
return new DocumentClient( { | |
// ensures empty values (userId = null) are converted | |
// more @ https://stackoverflow.com/questions/37479586/nodejs-with-dynamodb-throws-error-attributevalue-may-not-contain-an-empty-strin | |
convertEmptyValues: true | |
}); | |
}; |
This file contains 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
service: solving-marketing-attribution | |
custom: | |
# sma = Solving Marketing Attribution | |
tableIdentify: 'sma-identify-${self:provider.stage}' | |
tablePage: 'sma-event-page-${self:provider.stage}' | |
provider: | |
name: aws | |
runtime: nodejs10.x |
This file contains 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
const dynamoDBFactory = require('./src/dynamodb.factory'); | |
const dynamoDb = dynamoDBFactory(); | |
const { withStatusCode } = require('./src/utils/response.util'); | |
const { parseWith } = require('./src/utils/request.util'); | |
const parseJson = parseWith(JSON.parse); | |
const ok = withStatusCode(200); | |
const problem = withStatusCode(400); |
This file contains 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
service: segment-attribution | |
plugins: | |
- serverless-offline | |
custom: | |
tableIdentify: 'segment-event-identify-${self:provider.stage}' | |
tablePage: 'segment-event-page-${self:provider.stage}' | |
tableAttribution: 'segment-event-attribution-${self:provider.stage}' | |
tableUserMapping: 'segment-event-user-map-${self:provider.stage}' |
This file contains 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
const { unmarshallNewImageEvent } = require('./src/utils/dynamo_stream.util'); | |
const dynamoDBFactory = require('./src/dynamodb.factory'); | |
const { UserToAnonymousModel } = require('./src/models/UserToAnonymous'); | |
const dynamoDb = dynamoDBFactory(); | |
const model = new UserToAnonymousModel(dynamoDb); | |
module.exports.handler = async (event) => { | |
const eventData = event.Records[0]; | |
const eventAddedUnmarshalled = unmarshallNewImageEvent(eventData); |
This file contains 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
//src/models/UserToAnonymous.js | |
const USER_MAP_TABLE = process.env.USER_MAP_TABLE; | |
class UserToAnonymousModel { | |
get _baseParams() { | |
return { | |
TableName: USER_MAP_TABLE | |
}; | |
} |
This file contains 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
// /src/utils/dynamo_stream.util.js | |
const AWS = require('aws-sdk'); | |
const unmarshallNewImageEvent = (eventData) => { | |
if (!eventData.dynamodb) { | |
throw new Error('Not a dynamo event'); | |
} | |
// if you want the raw event we need to unmarshall it | |
// more @ https://stackoverflow.com/questions/44535445/unmarshall-dynamodb-json |
This file contains 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
// /src/utils/dynamo_stream.util.js | |
const AWS = require('aws-sdk'); | |
const unmarshallNewImageEvent = (eventData) => { | |
if (!eventData.dynamodb) { | |
throw new Error('Not a dynamo event'); | |
} | |
// if you want the raw event we need to unmarshall it | |
// more @ https://stackoverflow.com/questions/44535445/unmarshall-dynamodb-json |
This file contains 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
// src/utils/referrer_detection.util.js | |
const inbound = require('prezly-inbound'); | |
module.exports = async(href, referrer) => { | |
console.log('going extraction', href, referrer); | |
return new Promise((resolve, reject) => { | |
inbound.referrer.parse(href, referrer, (error, data) => { | |
if (error) { |