Last active
December 21, 2015 21:42
-
-
Save kelkingtron/6750bb07c1397d93d9c7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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