Skip to content

Instantly share code, notes, and snippets.

@arnarthor
Created March 26, 2018 10:57
Show Gist options
  • Save arnarthor/f3fa40a40e05894c4b80a12979f12a6b to your computer and use it in GitHub Desktop.
Save arnarthor/f3fa40a40e05894c4b80a12979f12a6b to your computer and use it in GitHub Desktop.
var amplitude = require('amplitude-js');
var apiKey;
exports.init = function init(key) {
apiKey = key;
amplitude.getInstance(apiKey).init(apiKey);
};
exports.client = amplitude;
exports.logEventWithUserProperties = function logEventWithUserProperties(
eventName,
eventProperties,
userProperties
) {
if (userProperties !== null && userProperties !== undefined) {
amplitude.getInstance(apiKey).setUserProperties(userProperties);
}
amplitude.getInstance(apiKey).logEvent(eventName, eventProperties);
};
exports.logEvent = function logEvent(eventName, eventProperties) {
amplitude.getInstance(apiKey).logEvent(eventName, eventProperties);
};
function _logRevenue(productId, quantity, price, revenueType, eventProperties) {
var revenue = new amplitude.Revenue().setQuantity(quantity).setPrice(price);
if (productId !== null && productId !== undefined && productId.length !== 0) {
revenue.setProductId(productId);
}
if (
revenueType !== null &&
revenueType !== undefined &&
revenueType.length !== 0
) {
revenue.setRevenueType(revenueType);
}
if (eventProperties !== null && eventProperties !== undefined) {
revenue.setEventProperties(eventProperties);
}
amplitude.logRevenueV2(revenue);
}
exports.logRevenueWithUserProperties = function logRevenueWithUserProperties(
productId,
quantity,
price,
revenueType,
eventProperties,
userProperties
) {
if (userProperties !== null && userProperties !== undefined) {
amplitude.getInstance(apiKey).setUserProperties(userProperties);
}
_logRevenue(productId, quantity, price, revenueType, eventProperties);
};
exports.logRevenue = _logRevenue;
exports.setUserId = function setUserId(userId) {
amplitude.getInstance(apiKey).setUserId(userId);
};
exports.setUserProperties = function setUserProperties(userProperties) {
amplitude.getInstance(apiKey).setUserProperties(userProperties);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment