<commit_before>require 'rubygems'
require 'base64'
require 'json'
require 'active_support'

module Mixpanel

  # A simple function for asynchronously logging to the mixpanel.com API.
  # This function requires `curl`.
  #
  # event: The overall event/category you would like to log this data under
  # properties: A hash of key-value pairs that describe the event. Must include 
  # the Mixpanel API token as 'token'
  #
  # See http://mixpanel.com/api/ for further detail.
  def track!(event, properties={})
    properties['ip'] = request.remote_ip rescue nil
    properties['mp_name_tag'] = current_user.login if user_signed_in?
    properties['rails env'] = Rails.env
    logger.info "Tracked: #{event} #{properties}"
    
    properties['token'] = '2b2e22dcf8cd5e3db82b017a44d57442'
    params = {"event" => event, "properties" => properties}
    data = Base64.strict_encode64(JSON.generate(params))
    request = "http://api.mixpanel.com/track/?data=#{data}"
    `curl -s '#{request}' &` # TODO: Use an event queue instead
  end
end<commit_msg>add mixpanel tracking<commit_after>require 'rubygems'
require 'base64'
require 'json'
require 'active_support'

module Mixpanel

  # A simple function for asynchronously logging to the mixpanel.com API.
  # This function requires `curl`.
  #
  # event: The overall event/category you would like to log this data under
  # properties: A hash of key-value pairs that describe the event. Must include 
  # the Mixpanel API token as 'token'
  #
  # See http://mixpanel.com/api/ for further detail.
  def track!(event, properties={})
    properties['ip'] = request.remote_ip rescue nil
    if user_signed_in?
      properties['mp_name_tag'] = current_user.login 
      properties['distinct_id'] = current_user.id
    end
    properties['rails env'] = Rails.env
    logger.info "Tracked: #{event} #{properties}"
    
    properties['token'] = '2b2e22dcf8cd5e3db82b017a44d57442'
    params = {"event" => event, "properties" => properties}
    data = Base64.strict_encode64(JSON.generate(params))
    request = "http://api.mixpanel.com/track/?data=#{data}"
    `curl -s '#{request}' &` # TODO: Use an event queue instead
  end
end
{'fraction_non_alphanumeric': 0.11883924458774758, 'fraction_numerical': 0.023030861354214647, 'mean_word_length': 3.9702517162471396, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6461829', 'n_tokens_mistral': 705, 'n_tokens_neox': 665, 'n_words': 202}