Mixpanel Integration or Plugin?


#1

Hi mates!

While I was looking to integrate Mixpanel, I’ve found this useful:
https://mixpanel.com/report/135980/setup/people/

and this:

http://codebrief.com/2012/10/ember-dot-js-analytics-integration/

Is anyone working on something like this? I would like to use Mixpanel and some user’s data posted to it

Update: I’ve installed the Mixpanel javascript between the head tags, and seems not working, not really sure why. I promise to update my developments on this here for the future, maybe this is the first mixpanel thread.


(Njoroge Kinyanjui) #2

Hey @PabloC Did you succeed integrating mixpanel and discourse?


(Yanivnizan) #3

We are also interested in this. Any updates here?


(Sam Saffron) #4

This could be done cleanly with our page tracker API:

Discourse.PageTracker.current().on('change', function(url) {
  console.log('the page changed to: ' + url);
});

You would include that in the footer of your site as a site customisation.


(Jordan Nunez) #6

Hey @sam , that has gotten us to start basic topic views through duck-typing:


window.MPtrackers = {
    home: function(title){
        mixpanel.track("Community - Home Page Viewed")
    },
    nav: function(path) {
        mixpanel.track("Community - Nav Clicked",{selected: path[0]})
    },
    category: function(title, path) {
        var pageInfo = title.substring(0, title.indexOf(" topics")).split(" ")
        var navType = pageInfo.shift()
        var catName = pageInfo.join(" ")
        mixpanel.track("Community - Category Viewed", {
            "Nav type": navType,
            "Name": catName
        });
    },
    topic: function(title, path) {
        var title = title.split(" - ");
        var props = {
            slug: path[1],
            topic_id: path [2],
            "Title": title[0],
            "Category": title[1],
        }
        mixpanel.track("Community - Topic Viewed", props);
    },
}
Discourse.PageTracker.current().on('change', function(url, title) {
    var dir = _.without(url.split("?")[0].split("/"), "")
    switch (dir[0]) {
        case undefined:
            MPtrackers.home(title);
            break
        case "categories":
        case "latest":
        case "top":
            MPtrackers.nav(dir);
            break
        case "c":
            MPtrackers.category(title, dir);
            break
        case "t":
            MPtrackers.topic(title, dir);
            break
    }
});s[campaign_keywords[index] + ' [first touch]'] = kw;
            }
        }
        mixpanel.register(params);
    }
    campaignParams();
</script>
```

However, this is only give us page views. We really want to dive into the good stuff like sign ups, topic created, and reply posted. I came across [this post](https://meta.discourse.org/t/wip-list-of-all-the-hooks-in-discourse/11505) however it doesn't seem like everything we need. There is a great request [post on it here](https://meta.discourse.org/t/event-hooks-for-discourse/8296/3?u=jordanmnunez). Do you have any suggestions? Any plans to integrate this? 

Is forking and digging into the back end our best bet?

Thanks!

Jordan

(Sam Saffron) #7

Sure try showing me a diff of what you need to achieve your logging and I will help you figure out how to write a customization to get the same thing going.


(Dean Taylor) #8

You might want to take a look a the JavaScript my post here:


(Jordan Nunez) #9

@DeanMarkTaylor that post is to a topic I created. It helped get me where I am but doesn’t help with the specific things I asked above. Thanks for the suggestion though.

I haven’t had time to dig into the discourse code, but I can try to see what I come up with. Thanks Sam.