Product Purchase Event

Send a product purchase event to Keen IO

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 = { 
  product: { // information we know about the product
    SKU: "9780061129735",
    name: "The Art of Loving",
    author: "Erich Fromm",
    category: "Books",
    price_in_usd: 12.99,
    added_from: {
      page_url: "https://myshop.com/Art-Loving-Erich-Fromm/",
      page_title: "The Art of Loving: Erich Fromm: 9780061129735"
    }
  },
  cart: { 
    id: "c00zzzbcinoin456zzz09cabc",
    created_date: "2017-05-18T18:14:33+00:00",
    item_count: 2,
    item_skus: ["9780061129735", "8723064529222"],
    total_purchase_value: 87.09,
    shipping: 0.0,
    tax: 16.26,
    order_total: 103.35
  },
  payment: {
    method: "credit_card"
  },
  user: { // information we know about the shopper
    id: "u90szabcinoin456asd09cabc",
    email: "ada@gmail.com", 
    name: {
      first: "Ada",
      last: "Sampson",
      full: "Ada Sampson"
    }
  },
  visitor_id: "f209nqw09awdcn0a9wneogiaadf", // aka uuid
  session: {
    id: "090szjawinoin112asd09cenw", 
    length_in_s : 788,
    initial_landing_page: "https://myshop.com/summer/"
  },
  keen: {
    timestamp: new Date().toISOString(), // the time the action occured
  },
  location: {
    city: "San Francisco",
    province: "California",
    country: "United States",
    continent: "North America",
    postal_code: "94122",
    coordinates: [-122.42005, 37.77479]
  }
}

// Record the event (send it to Keen IO)
client.recordEvent('product_purchases', 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...