Search code examples
ruby-on-railsrubyrubygemsanalyticsmixpanel

Using Ruby to get Mixpanel property data beyond event counts


Am using the "mixpanel_client" gem to get data for my core events, such as

['Landing: 1. page opened', 'Landing: 2. go pressed']

This works fine.

Now I want to get the initial referring domain, to understand where my users are coming from.

I have seen the property $initial_referring_domain in the JS API documentation.

I'd to be able to get something like:

  response = client.request(
              'events/properties',
              event:     'Game end',
              property: '$initial_referring_domain',
              name:      '',
              # values:    '',
              type:      'general',
              unit:      'day',
              from_date: a_week_ago,
              to_date:   today,
              format: 'json',
              limit:     7
              )

Is this possible using the mixpanel_client Ruby gem? I have an idea that I might need to use another API (the general api rather than the Data export one).

Can anyone shed light on how to use the Ruby gem to get data beyond mere event counts?

ps I have a site that generates specific beta keys for users (rather than tracking them as signed up users).


Solution

  • How about this?

    response = client.request(
      'events/properties',
      event:     'Game end',
      name:      '$initial_referring_domain',
      type:      'general',
      unit:      'day',
      interval:  1,
      limit:     7
    )
    p response
    

    If you check the docs, you can see that this example includes all required fields, plus limit (since you were including that):

    https://mixpanel.com/docs/api-documentation/data-export-api#event-properties-default

    If you just want to take a quick peek at the properties returned by default, try:

    top = client.request(
      'events/properties/top',
      event: 'Game end'
    )
    p top