Complete Level Event
Send an event to Keen when a player completes a level in your game.
HTML
<script src="https://d26b395fwzu5fz.cloudfront.net/keen-tracking-1.1.3.min.js"></script>
<div id='yeah'>
Practice writing/modifying a custom event. To send data to your own Keen project, create a free Keen account (https://keen.io) and change the projectID and writeKey to match your account. Press "Run" to send your event to Keen.
Check console for errors if you are stuck!
</div>
JavaScript
var client = new Keen({
projectId: '589d06518db53dfda8a8725d',
writeKey: '74D67280C9A4FC2A4CF200D05809A458A814DA683EF5EDE12C3F1FA8838E9B39E4EC6F9AE65CACBABF17C2061B5EE7D17F9E43CBFD2ADDE794A1AF148D4C1B1478897D874E1E7AF08AB2725650485DAE3D3004E6722F4E54EA13935AA83E68F5'
});
var event = {
level: {
number: 2,
difficulty_setting: 3
},
player: { // create a user object for details about this new player
id: "u90szabcinoin456asd09cabc",
email: "ada@airbnb.com",
name: {
first: "Ada",
last: "Sampson",
full: "Ada Sampson"
},
attribution: {
source: "in-app invite", // "direct download", "partner network", "facebook"
campaign: "friends_bonus_2A_2017"
},
accumulated_gameplay_hours: 3.4, // how much has this player played so far?
days_since_first_play: 0.3 // how many days old is this player account?
},
location: {
city: "San Francisco",
province: "California",
country: "United States",
continent: "North America",
postal_code: "94122",
coordinates: [-122.42005, 37.77479]
},
session: {
id: "090szjawinoin112asd09cenw"
},
keen: {
timestamp: new Date().toISOString(),
}
}
// Record the event (send it to Keen IO)
client.recordEvent('level_complete', event, function(err, res){ // name your collection here
if (err) {
document.getElementById('yeah').innerHTML = "Something is amiss. Check console for errors. Did you forget a comma perhaps? Or a curly brace?"
}
else {
document.getElementById('yeah').innerHTML = "You just sent an event to Keen IO!"
}
});