---
gallery: true
categories:
- webhook
---
## Tracks Logins in MixPanel

This rule will send a `Sign In` event to MixPanel, and will include the application the user is signing in to as a property. See [MixPanel HTTP API](https://mixpanel.com/help/reference/http) for more information.


```
function (user, context, callback) {

  var mpEvent = {
    "event": "Sign In",
    "properties": {
        "distinct_id": user.user_id,
        "token": "{REPLACE_WITH_YOUR_MIXPANEL_TOKEN}",
        "application": context.clientName
    }
  };

  var base64Event = new Buffer(JSON.stringify(mpEvent)).toString('base64');

  request.get({
    url: 'http://api.mixpanel.com/track/',
    qs: {
      data: base64Event
    }
  });
}

// don’t wait for the MixPanel API call to finish, return right away (the request will continue on the sandbox)`
callback(null,user,context);
```

---
gallery: true
categories:
- webhook
---
## Tracks Logins in MixPanel

This rule will send a `Sign In` event to MixPanel, and will include the application the user is signing in to as a property. See [MixPanel HTTP API](https://mixpanel.com/help/reference/http) for more information.


```
function (user, context, callback) {

  var mpEvent = {
    "event": "Sign In",
    "properties": {
        "distinct_id": user.user_id,
        "token": "{REPLACE_WITH_YOUR_MIXPANEL_TOKEN}",
        "application": context.clientName
    }
  };

  var base64Event = new Buffer(JSON.stringify(mpEvent)).toString('base64');

  request.get({
    url: 'http://api.mixpanel.com/track/',
    qs: {
      data: base64Event
    }
  }, function (e, r, b){
      // don’t wait for the MixPanel API call to finish, return right away (the request will continue on the sandbox)`
      callback(null, user, context);
  });
}
```

Move callback() invocation into request.get()
Move callback() invocation into request.get()

I was working with the Tracks Logins in MixPanel rule
on the website and the callback() invocation was
throwing three errors (callback not defined,
user not defined, context not defined), and upon
invocation was failing with:
 ERROR: Invalid response code from the auth0-sandbox: HTTP 400.
 Unable to compile submitted JavaScript.
 SyntaxError: Unexpected identifier SyntaxError: Unexpected identifier
I modified the script as in this request and it worked.

This change, if valid, will probably need to be applied to
other places as well, like the website.
