kissmetrics / km Goto Github PK
View Code? Open in Web Editor NEWKISSmetrics API - Ruby gem
License: Apache License 2.0
KISSmetrics API - Ruby gem
License: Apache License 2.0
That's inefficient.
I woke up this morning to see all our builds fail and deploy impossible because kmts
has been yanked. see here http://rubygems.org/gems/kmts - what's the alternative? is the january release of the km
gem thread-safe? this is a big headache for me, and there seems to be no documentation on the yank or the alternative that I can find.
The use of mutable class instance variables means that KM is not threadsafe. Class instance variables are shared between threads. This is particularly troublesome for the @id
variable, which is mutated by KM.identify()
. Here's an example that demonstrates the problem:
KM.init("1234", log_dir: ".")
10.times.map do |n|
Thread.new(n) do |thread_id|
KM.identify(thread_id)
sleep(1)
KM.record("Test")
end
end.each(&:join)
After running that, I would expect to see 10 unique URLs in kissmetrics_development_sent.log
. Instead, I see 10 URLs with the same _p
parameter:
/e?_n=Test&_p=9&_k=1234&_t=1346454179
/e?_n=Test&_p=9&_k=1234&_t=1346454179
/e?_n=Test&_p=9&_k=1234&_t=1346454179
/e?_n=Test&_p=9&_k=1234&_t=1346454179
/e?_n=Test&_p=9&_k=1234&_t=1346454179
/e?_n=Test&_p=9&_k=1234&_t=1346454179
/e?_n=Test&_p=9&_k=1234&_t=1346454179
/e?_n=Test&_p=9&_k=1234&_t=1346454179
/e?_n=Test&_p=9&_k=1234&_t=1346454179
/e?_n=Test&_p=9&_k=1234&_t=1346454179
Add KM.init('KM_KEY') to a before_filter in application controller
Add km gem to gemfile
bundle
run server, visit localhost
Notice: Page loads as expected
Change 'km' to 'kmts' in gemfile
bundle
run server, visit localhost
It appears that including the kmts gem does not work at all; does the documentation need updated or the gem have an issue?
Hey
I was wondering why did you rename the gem to kmts instead of increasing version number of km?
The currently published gem contains an early exit when sending requests if the environment is not production.
From: /Users/jroes/.rbenv/versions/1.9.3-p194-perf/lib/ruby/gems/1.9.1/gems/km-1.1.2/lib/km.rb @ line 214 KM.send_query:
214: def send_query(line)
215: if @env != 'production'
=> 216: log_sent(line)
217: return
218: end
This leads to confusion when testing in the development environment as requests don't actually make it to the KISSmetrics Live panel.
Unfortunately, the documented way how to include and require the kmts gem doesn't work. The following line in the Gemfile throws an error ('km' not found)
gem 'kmts', '~> 1.0.0', require: "km"
This library rescues Exception all over the place, oftentimes not re-raising it. This is problematic since it'll swallow interrupts and prevent threads from exiting properly. You should really only rescue StandardError unless you intend on re-raising the exception.
Hi KM,
I had a few issues with your gem and eventually decided it was easier to create my own code to interface with Kissmetrics and would like to share it with you what the problems were and what I came up with.
The first problem was around environments and the use of logs and cron and I had to work around the fact that the code executes differently in production. I would recommend that rather than hardcode behavior around environments to make this configurable instead. For example, I use an environment called 'staging' which should behave exactly like production, except it has a different name.
Also, as you may know, Heroku only allows hourly cron jobs so that meant the stats were not instant. And then I didn't see a distinct advantage to holding the logs in a file since they are sent one-by-one anyway. Finally, using the file system, in particular the tmp dir for storing the log posed the potential problem of logs possibly being deleted by automatic cleanup processes.
Because Heroku works well with delayed_job, that was my preferred method for sending metrics.
So please find my version of the KM class in the gist below. It's a bit of a work in progress since it only does what I need but so far it works well for me.
https://gist.github.com/1170061 (required: delayed_job and httparty gems)
Thanks,
Vincent
Hi, I noticed that the documentation says that syntax like KM.record('[email protected]', 'Viewed Homepage')
is acceptable, but reading through the code, it seems like this is not the case. The correct syntax is:
KM.identify('[email protected]')
KM.record('Viewed Homepage')
I could submit a pull request fixing this, but it seems just as simple to open a PR making the code behave as documented (which I prefer). Is this an actual issue?
Hey,
Could you please add a license to the km gem?
Thanks.
Hi,
Today we encountered an issue with lengthy parameters data.
In one of our reports to KM we send one of the parameters we get on our API. At some point we started seing large timeouts. After some careful evaluation we found these on the logs:
<Mon Nov 19 12:29:12 2012> End of file reached for host trk.kissmetrics.com:80
This was due to the fact that kissmetrics send metrics via get request and as such all parameters are sent on the URL. URL's have a length limit http://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url
Is there anyway around this?
Thank you.
Hi.
I have a very simple setup where I have a before_filter in ApplicationController that sets up KM.identify based on cookies/deviceId.
Users can 'like' something which would trigger email notifications which I would like to mark as sent. In this setup I want to do something like KM.record_with_identity(identity, 'Sent notification email') without affecting the KM that was initialized in the ApplicationController.
Here is a function that makes this work, sorry for not forking/requesting commit.
def record_with_identity(id,action,props={})
temp_id = @id
@id = id
record(action, props)
@id = temp_id
end
Hi there, we're posting in something like Michael Leung, and when we run reports in the KM admin it shows as Michael+Leung. Any insight would be great. We've tried it with the JavaScript API and it doesn't seem to gsub the space. Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.