Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails 3 compatibility? #28

Closed
agnessa opened this issue Jul 9, 2014 · 6 comments
Closed

Rails 3 compatibility? #28

agnessa opened this issue Jul 9, 2014 · 6 comments

Comments

@agnessa
Copy link

agnessa commented Jul 9, 2014

Tried to integrate ahoy 1.0.1 into a Rails 3 application running ruby 2.0.0 and connecting to Postgres 9.3 and ran into some issues, so I thought I'd ask whether these are known issues or incompatibilities.

For a start, I believe I managed to deal with the errors raised in migrations about the json & uuid tupes. Adding "serialize" to the event model fixed saving the event record. I managed to successfully record visits and events, but randomly there are exceptions and data is not saved. This is what I see in the rails log:

Started POST "/ahoy/visits" for 127.0.0.1 at 2014-07-09 15:47:58 +0100
Processing by Ahoy::VisitsController#create as JSON
  Parameters: {"visit_token"=>"acb62091-d764-46b9-8816-390e215569f4", "visitor_token"=>"19d8485b-52d5-4f63-8c2c-b5817e2619d2", "platform"=>"Web", "landing_page"=>"http://localhost:3000/species#/taxon_concepts/12088/legal", "screen_width"=>"1920", "screen_height"=>"1080"}
DEPRECATION WARNING: You're trying to create an attribute `'. Writing arbitrary attributes on a model is deprecated. Please just use `attr_writer` etc. (called from write_attribute at /home/agnessa/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-3.2.18/lib/active_record/attribute_methods/write.rb:32)
  User Load (0.4ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 3 LIMIT 1
   (0.2ms)  BEGIN
  SQL (0.4ms)  INSERT INTO "ahoy_visits" ("browser", "city", "country", "device_type", "id", "ip", "landing_page", "os", "referrer", "referring_domain", "region", "search_keyword", "started_at", "user_agent", "user_id", "utm_campaign", "utm_content", "utm_medium", "utm_source", "utm_term", "visitor_id") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21)  [["browser", "Firefox"], ["city", nil], ["country", "Reserved"], ["device_type", "Desktop"], ["id", nil], ["ip", "127.0.0.1"], ["landing_page", "http://localhost:3000/species#/taxon_concepts/12088/legal"], ["os", "Ubuntu"], ["referrer", nil], ["referring_domain", nil], ["region", nil], ["search_keyword", nil], ["started_at", Wed, 09 Jul 2014 14:47:58 UTC +00:00], ["user_agent", "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:30.0) Gecko/20100101 Firefox/30.0"], ["user_id", 3], ["utm_campaign", nil], ["utm_content", nil], ["utm_medium", nil], ["utm_source", nil], ["utm_term", nil], ["visitor_id", "19d8485b-52d5-4f63-8c2c-b5817e2619d2"]]
   (0.1ms)  ROLLBACK
Completed 500 Internal Server Error in 31.7ms

NoMethodError - undefined method `' for #

If it helps this is how I integrated ahoy: unepwcmc/SAPI@305cc41

Would be great to get this working! Thank you for the great work.

@ankane
Copy link
Owner

ankane commented Jul 10, 2014

Looks like id not being populated correctly. I'll see if I can troubleshoot. ["id", nil]

@agnessa
Copy link
Author

agnessa commented Jul 10, 2014

Thank you! Page refresh seems to trigger this most of the time, which makes me wonder whether javascript loading / execution order might have something to do with this. Any hints on when the ahoy.js methods should be called?

@ankane
Copy link
Owner

ankane commented Jul 10, 2014

You should be able to call them at any time. The library queues up events until the visit is created.

ankane added a commit that referenced this issue Jul 10, 2014
@ankane
Copy link
Owner

ankane commented Jul 10, 2014

For Rails 3, the normal ActiveRecord store will work best. Still not sure about the internal server error, but let me know if you keep seeing it with the other store.

@agnessa
Copy link
Author

agnessa commented Jul 10, 2014

Thank you for the hint. I ended up overriding the track_visit and track_event methods in the ActiveRecord store, and that allowed to to finally discover the issue with disappearing id. Fixed by replacing this:

        visit =
          visit_model.new do |v|
            v.id = ahoy.visit_id
            v.visitor_id = ahoy.visitor_id
            v.user = user if v.respond_to?(:user=)
            v.started_at = options[:started_at]
          end

with this:

    visit = visit_model.new(
      {
        id: ahoy.visit_id,
        visitor_id: ahoy.visitor_id,
        user: user,
        started_at: options[:started_at]
      },
      :without_protection => true
    )

and analogically for events. I used to think the 2 forms of new were interchangeable, but I'm not digging any further - glad it finally worked!

@ankane
Copy link
Owner

ankane commented Aug 19, 2014

Cleaning up issues

@ankane ankane closed this as completed Aug 19, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants