Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reaction logging refactored #20

Merged
merged 7 commits into from
Mar 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions generators/sendgrid_analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,30 @@ var bodyParser = require('body-parser')
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
var default_bcc = "open-growth-activity";

// Returns a string of the link name that was clicked in an email
var getUrlLabel = function ( url ) {
var delimiter;

if ( url.indexOf("&link=") > -1 ) {
delimiter = "&";
}
else if ( url.indexOf("?link=") > -1 ) {
delimiter = "?";
}
else {
return "unlabeled";
}

var parameters = url.split(delimiter+"link=")[1];
var kv = parameters.split(/&|=/);
var link = kv[0];
return link;
}

// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// SendGrid
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
module.exports = function (app) {
module.exports = function ( app ) {
// Tell express to use the body-parser middleware
app.use(bodyParser.json());

Expand All @@ -28,12 +48,17 @@ module.exports = function (app) {
continue;
}

actions.push({
var formattedAction = {
"email" : action.email,
"category" : action.category,
"event" : action.event,
"url" : action.url
});
"event" : action.event
};

if ( action.url ) {
formattedAction["url"] = getUrlLabel(action.url);
}

actions.push(formattedAction);
}

if ( actions.length === 0 ) {
Expand Down
2 changes: 1 addition & 1 deletion handlers/delights.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default request => {
// such as running ./signals/import.js then
// we don't need to lookup a customer record
if (!email) {
opengrowth.track.signal( `no-email.${signal}`, message );
//opengrowth.track.signal( `no-email.${signal}`, message );
return opengrowth.signals[signal]( request )
.then(() => {
return opengrowth.modules.librato(opengrowth.libratoUpdates);
Expand Down
5 changes: 3 additions & 2 deletions helpers/tracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ opengrowth.track.delight = ( delight, signal, data ) => {
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Track Reactions
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
opengrowth.track.reaction = (what_goes_here) => {
return track(`reactions`);
opengrowth.track.reaction = ( reaction, data ) => {
opengrowth.log(reaction, "reaction", data);
return track(`reactions.${reaction}`);
};
3 changes: 1 addition & 2 deletions signals/block1day.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ opengrowth.signals.block1day = ( request, customer ) => {
blocks_name_array.push(`${block.block_name}`);
blocks_url_array.push(`https://admin.pubnub.com/#/user/` +
`${block.user_id}/account/${block.account_id}/app/${block.app_id}` +
`/key/${block.app_key_id}/block/${block.block_id}/event_handlers` +
`?link=block`);
`/key/${block.app_key_id}/block/${block.block_id}/event_handlers`);
}

let firstName = opengrowth.customer.getFirstName(customer);
Expand Down
3 changes: 1 addition & 2 deletions signals/block3day.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ opengrowth.signals.block3day = ( request, customer ) => {
blocks_name_array.push(`${block.block_name}`);
blocks_url_array.push(`https://admin.pubnub.com/#/user/` +
`${block.user_id}/account/${block.account_id}/app/${block.app_id}` +
`/key/${block.app_key_id}/block/${block.block_id}/event_handlers` +
`?link=block`);
`/key/${block.app_key_id}/block/${block.block_id}/event_handlers`);
}

let firstName = opengrowth.customer.getFirstName(customer);
Expand Down
3 changes: 1 addition & 2 deletions signals/blockexpired.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ opengrowth.signals.blockexpired = ( request, customer ) => {
blocks_name_array.push(`${block.block_name}`);
blocks_url_array.push(`https://admin.pubnub.com/#/user/` +
`${block.user_id}/account/${block.account_id}/app/${block.app_id}` +
`/key/${block.app_key_id}/block/${block.block_id}/event_handlers` +
`?link=block`);
`/key/${block.app_key_id}/block/${block.block_id}/event_handlers`);
}

let firstName = opengrowth.customer.getFirstName(customer);
Expand Down
37 changes: 17 additions & 20 deletions signals/sendgrid_analytics.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,31 @@
opengrowth.signals.sendgrid_analytics = ( request ) => {
// Tracks status of an email sent to a customer through SendGrid
const categoryEvent = ( action ) => {
opengrowth.track.signal(`sendgrid_analytics.${action.category}.${action.event}`);
opengrowth.track.reaction(`sendgrid_analytics.${action.category}.${action.event}`, "swu-event-webhook");
let message = getLogMessage(action);
opengrowth.log("sendwithus.email", "reaction", message);
}

// Tracks a clicked link event in a SendGrid email
const signalLink = ( action ) => {
let link = getUrlParams(action.url);
opengrowth.track.signal(`sendgrid_analytics.${action.category}.link.${link}`);
opengrowth.track.reaction(`sendgrid_analytics.${action.category}.click.${action.url}`, "swu-event-webhook");
let message = getLogMessage(action);
opengrowth.log("sendwithus.email", "reaction", message);
}

// Returns a string of the link name that was clicked in an email
const getUrlParams = ( url ) => {
var delimiter;
// Parses Reaction data for logs
let getLogMessage = ( action ) => {
let log = {
"contact" : action.email
, "delight" : "sendwithus.email"
, "signal" : action.category
, "type" : action.event
};

if ( url.indexOf("&link=") > -1 ) {
delimiter = "&";
}
else if ( url.indexOf("?link=") > -1 ) {
delimiter = "?";
}
else {
return "unlabeled";
}
if ( action.url ) log["message"] = action.url;

let parameters = url.split(delimiter+"link=")[1];
let kv = parameters.split(/&|=/);
let link = kv[0];
return link;
}
return log;
};

var handlers = {
"click" : signalLink
Expand Down
2 changes: 1 addition & 1 deletion signals/signup.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ opengrowth.signals.signup = ( request, customer ) => {
`?utm_source=EmailBlasts%20&utm_medium=` +
`Open-Growth&utm_campaign=` +
`EB-CY16-Q4-Open-Growth-01&utm_term=link2` +
`&utm_content=api-keys&signal=signup&link=keys`;
`&utm_content=api-keys`;

var template_data = {
"customer_first_name" : firstName
Expand Down