Skip to content

Commit

Permalink
feat(plugin-metrics): add support for pre-login and aliasing endpoint…
Browse files Browse the repository at this point in the history
…s for metrics
  • Loading branch information
Carter Foxgrover committed Jan 17, 2017
1 parent 72afa01 commit 63ec1ef
Showing 1 changed file with 51 additions and 2 deletions.
53 changes: 51 additions & 2 deletions packages/plugin-metrics/src/metrics.js
Expand Up @@ -26,16 +26,65 @@ const Metrics = SparkPlugin.extend({
return this.batcher.request(Object.assign({key}, value));
},

submitClientMetrics(eventName, props) {
submitClientMetrics(eventName, props, preLoginId) {
const payload = {metricName: eventName};
if (props.tags) {
payload.tags = props.tags;
}
if (props.fields) {
payload.fields = props.fields;
}
return this.clientMetricsBatcher.request(payload);
if (props.type) {
payload.type = props.type;
}
if (preLoginId) {
const _payload = {
metrics: [
payload
]
};
// Do not batch these because pre-login events occur during onboarding, so we will be partially blind
// to users' progress through the reg flow if we wait to persist pre-login metrics for people who drop off because
// their metrics will not post from a queue flush in time
this.postPreLoginMetric(_payload, preLoginId);
} else {
return this.clientMetricsBatcher.request(payload);
}
},


/**
* Issue request to alias a user's pre-login ID with their CI UUID
* @param {string} preLoginId
*/
alias: function(preLoginId) {
var req = this.request({
method: `POST`,
api: `metrics`,
resource: `clientmetrics`,
headers: {
"X-Prelogin-UserId": preLoginId
},
body: {}
});
req.setParameter("alias", true);
return req;
},

postPreLoginMetric: function(payload, preLoginId) {
return this.request({
method: `POST`,
url: 'https://metrics-a.wbx2.com/metrics/api/v1/clientmetrics-prelogin',
headers: {
"X-Prelogin-UserId": preLoginId,
"content-type": "application/json",
"charset": "utf-8"
},
body: payload
});
}


});

export default Metrics;

0 comments on commit 63ec1ef

Please sign in to comment.