Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

ADDED - Alias method + bumped version

  • Loading branch information...
commit 1a023e72c8fe7d94c2b618f28faf1c0eee811087 1 parent 38243ed
@glesperance authored
Showing with 33 additions and 4 deletions.
  1. +32 −3 lib/mixpanel-client.js
  2. +1 −1  package.json
View
35 lib/mixpanel-client.js
@@ -13,7 +13,7 @@ var MixpanelPeople = require('./mixpanel-people')
, MIXPANEL_DATA_API_HOST = 'data.mixpanel.com'
, MIXPANEL_API_PORT = 80
- , DEBUG_MODE = 0
+ , DEBUG_MODE = 1
;
var globalAPIToken
@@ -45,6 +45,7 @@ function formatDate(d) {
}
function encodeDates(obj) {
+ console.log('--->', obj)
_.each(obj, function (v, k) {
if (v instanceof Date)
obj[k] = formatDate(v);
@@ -359,6 +360,34 @@ MixpanelClient.prototype.get_distinct_id = function () {
}
/***
+ * Creates an alias from one ID to the user's existing ID.
+ * This allows you to use your own IDs to identify users without breaking
+ * funnels and retention.
+ *
+ * @param {String} uniqueId A string that uniquely identifies the user, such as
+ * the user's ID in your database.
+ */
+MixpanelClient.prototype.alias = function () {
+ var args = Array.prototype.slice.call(arguments)
+ , callback = typeof args[args.length - 1] === 'function'
+ ? args.pop()
+ : undefined
+
+ , alias = args.shift()
+ , distinctId = args.shift()
+
+ if (typeof distinctId === 'undefined')
+ distinctId = this.get_distinct_id()
+
+ this.register({ __alias : alias })
+
+ return this.track("$create_alias", {
+ alias : alias
+ , distinct_id : distinctId
+ }, callback)
+}
+
+/***
* Identify a user with a unique ID. All subsequent events sent by this user
* will be tied to the new identity. If this method is not called, unique users
* will be identified by a UUID generated the first time they visit your site.
@@ -452,7 +481,7 @@ function MixpanelClient() {
this.req = req;
this.res = res;
- this.MIXPANEL_COOKIE_NAME = 'mp_' + this.APIToken + '_mixpanel';
+ this.MIXPANEL_COOKIE_NAME = 'mp_' + (this.APIToken || globalAPIToken) + '_mixpanel';
if (this.req)
this.COOKIE_OPTIONS = {
@@ -478,4 +507,4 @@ function MixpanelClient() {
/* ========================================================================== */
/* ========================================================================== */
-module.exports = MixpanelClient;
+module.exports = MixpanelClient;
View
2  package.json
@@ -2,7 +2,7 @@
, "description" : "A simple client for mixpanel's tracking & export API. Also supports exporting via streams."
, "keywords" : ["mixpanel", "analytics", "api", "stats", "export", "stream"]
-, "version" : "0.2.0"
+, "version" : "0.2.1"
, "homepage" : "https://github.com/glesperance/mixpanel-client"
, "repository" : { "type" : "git"
Please sign in to comment.
Something went wrong with that request. Please try again.