quirkey / sammy

Sammy is a tiny javascript framework built on top of jQuery, It's RESTful Evented Javascript.
http://sammyjs.org
MIT License
2.99k stars 384 forks source link

Mixpanel plugin #151

Closed jpgarcia closed 11 years ago

jpgarcia commented 11 years ago

I've just added a new plugin for tracking page views on Mixpanel, hope you find it useful.

Also performed some tweaks on the Google Analytics plugin as I realized that when binding two 'event-context-after' events (e.g.:Google Analytics + Mixpanel plugins) you receive the path value as 'event-context-after' instead of the actual path on the 2nd plugin declared. So I updated to code to get the path from app.last_location[1] rather than from this.path.

Please let me know if there is a better approach to get this path and using both plugins at the same time.

jpgarcia commented 11 years ago

actually my app is not named app :) and it works as when you define the plugin in you're injecting the app as a parameter, but yes you're right this.app is much better.

To reproduce the issue:

  1. Create two plugins:

    (function($) {
     Sammy = Sammy || {};
    
     Sammy.PluginA = function(app) {
       this.bind('event-context-after', function() {
         console.log('PluginA path:' + this.path)
       });
     };
    })(jQuery);
    
    (function($) {
     Sammy = Sammy || {};
    
     Sammy.PluginB = function(app) {
       this.bind('event-context-after', function() {
         console.log('PluginB path:' + this.path)
       });
     };
    })(jQuery);
    
  2. Enable both in your app:

    this.use('PluginA');    
    this.use('PluginB');
  3. Run the app and you should get the following output:
  PluginA path:/#/home
  PluginB path:event-context-after 

I've just pushed the this.app update as you suggested.

jpgarcia commented 11 years ago

Hey guys, I've also added a new one for KISSmetrics

thanks!

endor commented 11 years ago

Ah, sorry about that. You are of course correct. Still this.app might be better, so thanks for that. Hm.. I am thinking, since you added another kind of tracking plugin, does it make more sense to create a separate repository for those and add a link in the README or a separate file in the plugins directory? I am not sure. It's nice to have everything in one place though. What do you think?

endor commented 11 years ago

@jpgarcia any thoughts on this? :)

jpgarcia commented 11 years ago

Hey endor! mmm I don't think so. I'd go for the option B (having a new file in plugins' folder and keep them in the same repo)

... Sorry about my delayed response! I must have forgotten to reply 4 months ago :)