Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mixpanel

Package Overview
Dependencies
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mixpanel - npm Package Compare versions

Comparing version 0.0.9 to 0.0.10

test/import.js

14

example.js

@@ -44,1 +44,15 @@ // grab the Mixpanel factory

mixpanel.track("test", function(err) { if (err) throw err; });
// import an old event
var mixpanel_importer = Mixpanel.init('valid mixpanel token', {
key: "valid api key for project"
});
mixpanel_importer.set_config({ debug: true });
// needs to be in the system once for it to show up in the interface
mixpanel_importer.track('old event', { gender: '' });
mixpanel_importer.import("old event", new Date(2012, 4, 20, 12, 34, 56), {
distinct_id: 'billybob',
gender: 'male'
});

56

lib/mixpanel-node.js

@@ -18,3 +18,3 @@ /*

if(!token) {
throw new Error("The Mixpanel Client needs a Mixpanel token");
throw new Error("The Mixpanel Client needs a Mixpanel token: `init(token)`");
}

@@ -45,2 +45,10 @@

};
if (endpoint === '/import') {
var key = metrics.config.key;
if (!key) {
throw new Error("The Mixpanel Client needs a Mixpanel api key when importing old events: `init(token, { key: ... })`");
}
request_data.api_key = key;
}

@@ -80,3 +88,3 @@ var request_options = {

---
this function sends an event to mixpanel
this function sends an event to mixpanel.

@@ -94,2 +102,5 @@ event:string the event name

// if properties.time exists, use import endpoint
var endpoint = (typeof(properties.time) === 'number') ? '/import' : '/track';
properties.token = metrics.token;

@@ -103,3 +114,3 @@ properties.mp_lib = "node";

if(metrics.config.debug) {
if (metrics.config.debug) {
console.log("Sending the following event to Mixpanel:");

@@ -109,5 +120,42 @@ console.log(data);

metrics.send_request('/track', data, callback);
metrics.send_request(endpoint, data, callback);
};
/**
import(event, properties, callback)
---
This function sends an event to mixpanel using the import
endpoint. The time argument should be either a Date or Number,
and should signify the time the event occurred.
It is highly recommended that you specify the distinct_id
property for each event you import, otherwise the events will be
tied to the IP address of the sending machine.
For more information look at:
https://mixpanel.com/docs/api-documentation/importing-events-older-than-31-days
event:string the event name
time:date|number the time of the event
properties:object additional event properties to send
callback:function(err:Error) callback is called when the request is
finished or an error occurs
*/
metrics.import = function(event, time, properties, callback) {
if (typeof(properties) === 'function' || !properties) {
callback = properties;
properties = {};
}
if (time === void 0) {
throw new Error("The import method requires you to specify the time of the event");
} else if (Object.prototype.toString.call(time) === '[object Date]') {
time = Math.floor(time.getTime() / 1000);
}
properties.time = time;
metrics.track(event, properties, callback);
};
metrics.people = {

@@ -114,0 +162,0 @@ /**

2

package.json

@@ -5,3 +5,3 @@ {

"keywords": ["mixpanel", "analytics", "api", "stats"],
"version": "0.0.9",
"version": "0.0.10",
"homepage": "https://github.com/carlsverre/mixpanel-node",

@@ -8,0 +8,0 @@ "author": "Carl Sverre",

@@ -58,2 +58,15 @@ Mixpanel-node

// import an old event
var mixpanel_importer = Mixpanel.init('valid mixpanel token', {
key: "valid api key for project"
});
// needs to be in the system once for it to show up in the interface
mixpanel_importer.track('old event', { gender: '' });
mixpanel_importer.import("old event", new Date(2012, 4, 20, 12, 34, 56), {
distinct_id: 'billybob',
gender: 'male'
});
Tests

@@ -78,2 +91,3 @@ -----

- [Nathan Rajlich](https://github.com/TooTallNate)
- [Thomas Watson Steen](https://github.com/watson)

@@ -80,0 +94,0 @@ License

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc