From a836b06d3e85acaea1d6a4c3d7eaaec47f48d561 Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Wed, 30 May 2012 17:32:07 -0700 Subject: [PATCH] mixpanel on posting --- app/assets/javascripts/app/models/post.js | 8 ++++++++ app/assets/javascripts/app/pages/framer.js | 12 +++++++++++ spec/javascripts/app/models/post_spec.js | 24 ++++++++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/app/assets/javascripts/app/models/post.js b/app/assets/javascripts/app/models/post.js index 71123457c..12ba81cc5 100644 --- a/app/assets/javascripts/app/models/post.js +++ b/app/assets/javascripts/app/models/post.js @@ -58,6 +58,14 @@ app.models.Post = Backbone.Model.extend(_.extend({}, app.models.formatDateMixin, preloadOrFetch : function(){ var action = app.hasPreload("post") ? this.set(app.parsePreload("post")) : this.fetch() return $.when(action) + }, + + hasPhotos : function(){ + return this.get("photos") && this.get("photos").length > 0 + }, + + hasText : function(){ + return $.trim(this.get("text")) !== "" } }), { headlineLimit : 118, diff --git a/app/assets/javascripts/app/pages/framer.js b/app/assets/javascripts/app/pages/framer.js index 73ed8247f..1dd3521e5 100644 --- a/app/assets/javascripts/app/pages/framer.js +++ b/app/assets/javascripts/app/pages/framer.js @@ -129,6 +129,18 @@ app.views.framerControls = app.views.Base.extend({ } this.$('input').prop('disabled', 'disabled') this.model.save() + + this.trackPost() + }, + + trackPost : function() { + var model = this.model + + app.track("Posted", { + text : model.hasText(), + photos : model.hasPhotos(), + template : model.get("frame_name") + }) }, inValidFrame : function(){ diff --git a/spec/javascripts/app/models/post_spec.js b/spec/javascripts/app/models/post_spec.js index c6f6ef14b..3eaea4559 100644 --- a/spec/javascripts/app/models/post_spec.js +++ b/spec/javascripts/app/models/post_spec.js @@ -36,4 +36,28 @@ describe("app.models.Post", function() { expect(this.post.createdAt()).toEqual(+date); }); }); + + describe("hasPhotos", function(){ + it('returns true if the model has more than one photo', function(){ + this.post.set({photos : [1,2]}) + expect(this.post.hasPhotos()).toBeTruthy() + }) + + it('returns false if the model does not have any photos', function(){ + this.post.set({photos : []}) + expect(this.post.hasPhotos()).toBeFalsy() + }) + }); + + describe("hasText", function(){ + it('returns true if the model has text', function(){ + this.post.set({text : "hella"}) + expect(this.post.hasText()).toBeTruthy() + }) + + it('returns false if the model does not have text', function(){ + this.post.set({text : " "}) + expect(this.post.hasText()).toBeFalsy() + }) + }); });