Skip to content

Instantly share code, notes, and snippets.

@kelkingtron
Last active December 21, 2015 21:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kelkingtron/6750bb07c1397d93d9c7 to your computer and use it in GitHub Desktop.
Save kelkingtron/6750bb07c1397d93d9c7 to your computer and use it in GitHub Desktop.
var soundCloudMunchkin = {
init: function(widget){
//save a reference to the widget
soundCloudMunchkin.widget = widget;
//Bind each relevant event to the corresponding method
widget.bind(SC.Widget.Events.PLAY, function(){
soundCloudMunchkin.trackPlay();
});
widget.bind(SC.Widget.Events.PAUSE, function(){
soundCloudMunchkin.trackPause();
});
widget.bind(SC.Widget.Events.FINISH, function(){
soundCloudMunchkin.trackFinish();
});
widget.bind(SC.Widget.Events.SEEK, function(){
soundCloudMunchkin.trackSeek();
});
widget.bind(SC.Widget.Events.CLICK_DOWNLOAD, function(){
soundCloudMunchkin.trackDownload();
});
widget.bind(SC.Widget.Events.CLICK_BUY, function(){
soundCloudMunchkin.trackBuy();
});
widget.bind(SC.Widget.Events.OPEN_SHARE_PANEL, function(){
soundCloudMunchkin.trackShareOpen();
});
},
trackActivity : function(action){
//set action param to be the string passed to the function
var qs = "action=" + action;
//use getCurrentSound callback to get the name of the current track
soundCloudMunchkin.widget.getCurrentSound(function(currentSound){
//add it to our querystring
qs = qs + "&sound=" + currentSound.title;
//use the getPosition callback to get the position of the track in ms
soundCloudMunchkin.widget.getPosition(function(position){
//add it to the querystring
qs = qs + "&position=" + position;
//assemble our data object for the munchkin activity
var dataObject = {
"url": "soundCloudInteraction",
"params": qs
}
//call the munchkinFunction to submit the activity
Munchkin.munchkinFunction("visitWebPage", dataObject);
});
});
},
//create individual methods for each event type
trackPlay : function(){
soundCloudMunchkin.trackActivity("play");
},
trackPause : function(){
soundCloudMunchkin.trackActivity("pause");
},
trackFinish : function(){
soundCloudMunchkin.trackActivity("finish");
},
trackSeek : function(){
soundCloudMunchkin.trackActivity("seek");
},
trackDownload : function(){
soundCloudMunchkin.trackActivity("download");
},
trackBuy : function(){
soundCloudMunchkin.trackActivity("buy");
},
trackShareOpen : function(){
soundCloudMunchkin.trackActivity("share_open");
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment