Skip to content

Instantly share code, notes, and snippets.

@frgooall
Created July 31, 2013 02:09
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 frgooall/6118776 to your computer and use it in GitHub Desktop.
Save frgooall/6118776 to your computer and use it in GitHub Desktop.
Mixpanel - Trying to get Event properties and People to track correctly The athlete controller is where I am recording events and people, could that be the issue?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><%= content_for?(:title) ? yield(:title) : "Yale Athletics - Admin" %></title>
<%= csrf_meta_tags %>
<!-- Le HTML5 shim, for IE6-8 support of HTML elements -->
<!--[if lt IE 9]>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.6.1/html5shiv.js" type="text/javascript"></script>
<![endif]-->
<%= stylesheet_link_tag "application", :media => "all" %>
<!-- For third-generation iPad with high-resolution Retina display: -->
<!-- Size should be 144 x 144 pixels -->
<%= favicon_link_tag 'apple-touch-icon-144x144-precomposed.png', :rel => 'apple-touch-icon-precomposed', :type => 'image/png', :sizes => '144x144' %>
<!-- For iPhone with high-resolution Retina display: -->
<!-- Size should be 114 x 114 pixels -->
<%= favicon_link_tag 'apple-touch-icon-114x114-precomposed.png', :rel => 'apple-touch-icon-precomposed', :type => 'image/png', :sizes => '114x114' %>
<!-- For first- and second-generation iPad: -->
<!-- Size should be 72 x 72 pixels -->
<%= favicon_link_tag 'apple-touch-icon-72x72-precomposed.png', :rel => 'apple-touch-icon-precomposed', :type => 'image/png', :sizes => '72x72' %>
<!-- For non-Retina iPhone, iPod Touch, and Android 2.1+ devices: -->
<!-- Size should be 57 x 57 pixels -->
<%= favicon_link_tag 'apple-touch-icon-precomposed.png', :rel => 'apple-touch-icon-precomposed', :type => 'image/png' %>
<!-- For all other devices -->
<!-- Size should be 32 x 32 pixels -->
<%= favicon_link_tag 'favicon.ico', :rel => 'shortcut icon' %>
<!-- Segment.io snippet -->
<script type="text/javascript">
var analytics=analytics||[];(function(){var e=["identify","track","trackLink","trackForm","trackClick","trackSubmit","page","pageview","ab","alias","ready","group"],t=function(e){return function(){analytics.push([e].concat(Array.prototype.slice.call(arguments,0)))}};for(var n=0;n<e.length;n++)analytics[e[n]]=t(e[n])})(),analytics.load=function(e){var t=document.createElement("script");t.type="text/javascript",t.async=!0,t.src=("https:"===document.location.protocol?"https://":"http://")+"d2dq2ahtl5zl1z.cloudfront.net/analytics.js/v1/"+e+"/analytics.min.js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(t,n)};
analytics.load("dche9ralpd");
</script>
<!-- start Mixpanel -->
<script type="text/javascript">(function(e,b){if(!b.__SV){var a,f,i,g;window.mixpanel=b;a=e.createElement("script");a.type="text/javascript";a.async=!0;a.src=("https:"===e.location.protocol?"https:":"http:")+'//cdn.mxpnl.com/libs/mixpanel-2.2.min.js';f=e.getElementsByTagName("script")[0];f.parentNode.insertBefore(a,f);b._i=[];b.init=function(a,e,d){function f(b,h){var a=h.split(".");2==a.length&&(b=b[a[0]],h=a[1]);b[h]=function(){b.push([h].concat(Array.prototype.slice.call(arguments,0)))}}var c=b;"undefined"!==
typeof d?c=b[d]=[]:d="mixpanel";c.people=c.people||[];c.toString=function(b){var a="mixpanel";"mixpanel"!==d&&(a+="."+d);b||(a+=" (stub)");return a};c.people.toString=function(){return c.toString(1)+".people (stub)"};i="disable track track_pageview track_links track_forms register register_once alias unregister identify name_tag set_config people.set people.set_once people.increment people.append people.track_charge people.clear_charges people.delete_user".split(" ");for(g=0;g<i.length;g++)f(c,i[g]);
b._i.push([a,e,d])};b.__SV=1.2}})(document,window.mixpanel||[]);
mixpanel.init("508c03196462312858de075f25bdf17d");</script>
<!-- end Mixpanel -->
<script type=”text/javascript”>
mixpanel.track_pageview;
</script>
<meta name="google-site-verification" content="dZYDcPBBt0StbUtELPTrAlAN-jevuJlrw0G0qBDVcow" />
</head>
<body>
<%= render "layouts/sidebar" %>
<%= render "layouts/top_bar" %>
<section id="main">
<%= bootstrap_flash %>
<%= yield %>
<%= render "layouts/footer" %>
</section>
<!-- Javascripts
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<%= javascript_include_tag "application" %>
</body>
</html>
class AthletesController < ApplicationController
before_filter :find_user_id
before_filter :find_ath_id
def edit
@sport = @user.athlete
end
def show
@sport = @user.athlete
end
def ncaa_form
send_file("#{Rails.root}/public/pdfs/ncaa_form.pdf", :disposition => "inline" , :target => '_blank', type: "application/pdf")
end
#should move this out of the controller and use the mixpanel ruby or javascript library?
def update
if @athlete.update(athletes_params)
redirect_to @athlete, notice: "Your information was updated successfully"
mixpanel.track 'User Updated', {
:distinct_id => @user.id,
:time => @user.updated_at
}
mixpanel.set ({ :distinct_id => @user.id, :email => @user.email, :first_name => @user.first_name, :last_name => @user.last_name})
else
flash[:error] = "Opps! Sorry #{@user.first_name} you forgot something on the, please complete all the required fields"
@sport = @user.athlete
render :show
end
end
private
def find_ath_id
@athlete = @user.athlete
end
def find_user_id
@user = current_user
end
# Never trust parameters from the scary internet, only allow the white list through.
def athletes_params
params.require(:athlete).permit(:race, :college, :perm_address, :perm_citystzip,
:perm_nation, :perm_phone, :cell_phone, :campus_box, :off_campus_address, :off_campus_citystzip,
:off_campus_rm, :parent_guardian_1_first, :parent_guardian_1_last, :parent_guardian_1_email, :parent_guardian_1_address,
:parent_guardian_1_citystzip, :parent_guardian_1_nation, :parent_guardian_2_first, :parent_guardian_2_last,
:parent_guardian_2_email, :parent_guardian_2_address, :parent_guardian_2_citystzip, :parent_guardian_2_nation, :ncaa, :ncaa_drug,
:ivy, :ins, :med, :sa_conduct
)
end
end
<title><%= page_title %></title>
<table class="table no-border">
<thead>
</thead>
<tbody>
<tr>
<td>Sport:</td>
<% @sport.sports.each do |s| %>
<td class="blue-text strong"><%= s.sport %></td>
<% end %>
<tr>
<td>Class:</td>
<td class="blue-text strong"><%= current_user.athlete.grad_yr %></td>
</tr>
<tr>
<td>Race:</td>
<td ><%= current_user.athlete.race %></td>
</tr>
<tr>
<td>College:</td>
<td><%= current_user.athlete.college %></td>
</tr>
<tr>
<td>Campus Box:</td>
<td><%= current_user.athlete.campus_box %></td>
</tr>
<tr>
<td><strong>Current Address:</strong></td>
<td>
<address>
<%= current_user.athlete.perm_address %><br>
<%= current_user.athlete.perm_citystzip %> <%= current_user.athlete.perm_nation %> <br>
<abbr title="Home Phone">P:</abbr> <%= current_user.athlete.perm_phone %><br>
<abbr title="Cell Phone">C:</abbr> <%= current_user.athlete.cell_phone %>
</address>
</td>
</tr>
<tr>
<td><strong>Off-Campus Address:</strong></td>
<td>
<address>
<%= current_user.athlete.off_campus_address %><br>
<%= current_user.athlete.off_campus_citystzip %><br>
<abbr title="Off Campus Room/Unit/Apt#">RM:</abbr> <%= current_user.athlete.perm_phone %><br>
</address>
</td>
</tr>
<tr>
<td>Your Avatar</td>
<td>
<%= image_tag @user.avatar.url %>
</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="2">
<div class="clearfix" style="padding: 0 5px;">
<div class="pull-left">
<a data-toggle="modal" href="#athlete_update" class="btn btn-medium light-blue inverse" type="button">Update</a>
<%= render 'athletes/athlete_update' %>
</div>
</div>
</td>
</tr>
</tfoot>
</table>
@frgooall
Copy link
Author

If I am going to use the mixpanel JS library, where should I put the snippets to record events? Or should I stick with using the Ruby gem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment