Skip to content

Instantly share code, notes, and snippets.

View digitalbase's full-sized avatar

Gijs Nelissen digitalbase

View GitHub Profile
<?php
use Prezly\Auth\Session\BackendSessionReference;
use Prezly\Command\Import\HandleRecord;
use Prezly\Task\BaseTask;
class importResumeRecordTask extends BaseTask
{
protected function configure()
{
// /src/handlers/segment/identifyUser.js
const { withStatusCode } = require('../../utils/response.util');
const ok = withStatusCode(200, JSON.stringify);
const {SegmentTracking} = require('../../SegmentTracking');
const SegmentTracker = new SegmentTracking();
exports.handler = async (event) => {
const { id } = event.pathParameters;
//src/handlers/segment/segment.serverless.yml
storeEvent:
handler: src/handlers/segment/storeEvent.handler
events:
- http: 'POST /events'
identifyUser:
handler: src/handlers/segment/identifyUser.handler
events:
- http: 'GET /segment/identify/user/{id}'
trackAnonymous:
service: ${env:SERVICE_NAME}
package:
exclude:
- data/**
- events/**
- .idea
plugins:
- serverless-offline
// src/SegmentTracking.js
const https = require('https');
const dynamoDBFactory = require('./dynamodb.factory');
const {UserToAnonymousModel} = require('./models/UserToAnonymous');
const {SourceAttributionModel} = require('./models/SourceAttribution');
const SOURCE_IDENTIFIED_EVENT_NAME = process.env.ANALYTICS_SOURCE_IDENTIFICATION_EVENT;
class SegmentTracking {
{
"type": "identify",
"userId": "[user_id]",
"properties": {
"source_first_referrer": null,
"source_first_referrer_client: "gmail"
"source_first_referrer_type": "email",
"source_first_campaign_source": "feedburner",
"source_first_campaign_medium": "feed",
"source_first_campaign_name": "Feed: contrast/blog (The Intercom Blog)",
{
"referrer": {
"type": "email",
"client": "gmail",
"from": "https://mail.google.com/_/mail-static/_/js/main/m_i,t/rt=h/ver=am293eyFlXI.en./sv=1/am=!v8Czf-oeNMn1FOzaNKsLQrJy-oNN3RSSYMAZTBUxCzwgQcXtLnTEHCkGr437GpFE2Dliuw/d=1",
"link": "http://blog.intercom.io/churn-retention-and-reengaging-customers/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+contrast%2Fblog+%28The+Intercom+Blog%29"
},
"campaign": {
"source": "feedburner",
"medium": "feed",
resources:
Resources:
SegmentIdentifiesDynamoDBTable:
Type: 'AWS::DynamoDB::Table'
Properties:
StreamSpecification:
StreamViewType: NEW_IMAGE
AttributeDefinitions:
- AttributeName: messageId
AttributeType: S
// src/tasks/import_identify_from_file.js
// copied from https://stackoverflow.com/questions/32678325/how-can-i-import-bulk-data-from-a-csv-file-into-dynamodb
const fs = require('fs');
const parse = require('csv-parse');
const async = require('async');
const CSV_FILENAME = process.argv[2];
const DYNAMODB_TABLENAME = 'sma-identify-event-dev';
// src/tasks/import_page_from_file.js
// copied from https://stackoverflow.com/questions/32678325/how-can-i-import-bulk-data-from-a-csv-file-into-dynamodb
const fs = require('fs');
const parse = require('csv-parse');
const async = require('async');
const CSV_FILENAME = process.argv[2];
const DYNAMODB_TABLENAME = 'sma-page-event-dev';