This week I'm in the process of moving one of my sites to Drupal 7. I'd like to take the Mixpanel analytics with it! I'm creating this issue and assigning it to myself so that no one else starts working a Drupal 7 port at the same time.

Because we're making the jump to Drupal 7, I'm going to do the following additional things:

  • Start with the Mixpanel 2.0 Javascript library - I understand then need for backwards compatibility in Drupal 6 land for deployed sites, but Drupal 7 means you have to rewrite everything anyway. Hopefully, we'll find a way to make this happen in Drupal 6 per #1849574: Upgrade Mixpanel Javascript to version 2.0
  • Use Queue API and drupal_http_request() to contact Mixpanel - This is basically the functionality that #1822434: Make mixpanel_track() implementation more Drupal-y does for Drupal 6 but since the Queue API is built in to Drupal 7, I don't personally see any arguments against doing this as it's much more portable (works under Windows and systems without command line curl).

If anyone objects to any of these assertions, please let me know! I won't be making a stable release for Drupal 7 for a couple weeks anyway, so we'll have plenty of time to discuss.

Please let me know what you think!

Regards,
David.

Comments

dsnopek’s picture

There is now a 7.x-1.x branch. The core 'mixpanel' module works fully and most of 'mixpanel_defaults'. I haven't been able to successfully test Organic Groups or Spaces under Drupal 7, so the 'og' bits in 'mixpanel_defaults' aren't fully ported or tested and 'mixpanel_spaces' looks like it should work (spaces APIs haven't changed) but I didn't test it.

I added a few additional changes in this branch:

  • Tracking for anonymous users - Mixpanel does a great job of this, we should support it too!
  • A new permission for the settings page - allows much more fine grained access control.

We can backport these features to the Drupal 6 branch later.

I'm going to keep this issue open until I can finish 'mixpanel_defaults' and 'mixpanel_spaces' because those are regressions.

incaic’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev

@dsnopek

What do you think about modifying mixpanel.js to use mixpanel.alias() ?
I set usealias in my own custom _js_alter() when needed, which is at first login as well as when changing username.

// Do some initial setup.
jQuery(document).ready(function() {

  // For authenticated users
  if (Drupal.settings.mixpanel.defaults.uid) {

    // Uniquely identify the user with name tag.
    if (typeof Drupal.settings.mixpanel.defaults.usealias !== 'undefined') {

      // use alias to use own user IDs without breaking funnels
      mixpanel.alias(Drupal.settings.mixpanel.defaults.mp_name_tag);
      delete Drupal.sdttings.mexpanel.defaults.use_alias;

    } else {

      // use own user IDs
      mixpanel.identify(Drupal.settings.mixpanel.defaults.mp_name_tag);

    }

    // Set human-readable name for user. (displayed in Streams)
    mixpanel.name_tag(Drupal.settings.mixpanel.defaults.mp_name_tag);

    // set user profile.
    mixpanel.people.set(Drupal.settings.mixpanel.people);

  }

  // Register properties about the user.
  mixpanel.register(Drupal.settings.mixpanel.defaults);

});
dsnopek’s picture

I definitely think mixpanel.alias() is useful, especially in conjunction with anonymous users! Thanks for the suggestion!

However, this should really be a seperate issue in the issue queue - this one is just about completing the Drupal 7 port. If you create a new issue and make a patch which also includes a new checkbox on the settings page to enable this, I'd definitely consider merging it. :-)

Thanks!

Regards,
David.

dsnopek’s picture

Now that #1874942: Include the mixpanel_rules module? has been merged, the mixpanel_rules module will also need to be updated to Drupal 7.

solovelyhere’s picture

Hiya -

sorry I'm new but was wondering how to actually integrate the dev module with drupal. I already installed it as well as configured it with my mixpanel token but mixpanel is still unable to detect it sending data?

Any help would be so much appreciated as I am rather desperate!

Thanks! (:

dsnopek’s picture

Hi @solovelyhere,

I don't think Mixpanel will detect that you've installed it until you send some events and by default the Mixpanel module just provides an API for sending events - it doesn't send any itself.

So, you can (1) install the "mixpanel_defaults" module which will send some precreated events, (2) use the "mixpanel_rules" module to create some Rules to send events or (3) write your own module which uses the provided API to send some events.

If you have any more questions, please open a new issue! (This issue is about finishing the Drupal 7 port, so it's not really the appropriate place for support)

Best regards,
David.

incaic’s picture

Finally got around to packaging this up. I also went ahead and made a few other non-critical mods.

http://drupal.org/node/1990628

It works great for me! :-)

EDIT: Referring to comment above: http://drupal.org/node/1858472#comment-6876310

dsnopek’s picture

I was finally able to setup Organic Group and test the integration in mixpanel_defaults! Everything is working now.

I also made the executive decision to simply remove 'mixpanel_spaces'.

The current supported 'spaces' for Drupal 7 doesn't work with the current supported 'og'! Also, the mixpanel_spaces_context_page_reaction() function appears to be Open Atrium 1.x specific and since Open Atrium 1.x is Drupal 6 only, this doesn't make any sense in the Drupal 7 version of this module!

In fact, I'd say the future of 'spaces' is pretty unclear right now.

If someone does successfully use 'spaces' for something in Drupal 7, they can pretty easily add the information this modules used to add in their custom module or with Rules...

dsnopek’s picture

Status: Active » Closed (fixed)

I finally got mixpanel_rules fully working under Drupal 7! This means that from a code perspective, everything necessary for a D7 release is finished. I'll make a 7.x-1.0-rc1 release in a moment.