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

Can't access event properties #86

Closed
mklemme opened this Issue Mar 19, 2015 · 7 comments

Comments

3 participants
@mklemme

mklemme commented Mar 19, 2015

I'm having trouble accessing event properties. I've assigned the result to a varaible e and tried everything to get properties but it returns TypeError: no implicit conversion of Hash into String. Any ideas?

Activerecord query

=> #<Ahoy::Event:0x000001037b3938
  id: "ff9ab428-01b7-4dc1-aefe-5af027d0a3c9",
  visit_id: "da53b65f-004e-4ac9-95b6-f88e2eb5a314",
  user_id: nil,
  name: "$view",#<Ahoy::Event:0x81bd9c9c>

I'm also using the example track_visit method provided:

def track_event(name, properties, options, &block)
    event =
    event_model.new do |e|
      e.id = options[:id]
      e.visit_id = ahoy.visit_id
      e.user = user
      e.name = name
      e.properties = properties.to_json
      e.time = options[:time]
    end
    yield(event) if block_given?
    begin
      event.save!
    rescue *unique_exception_classes
      # do nothing
    end
  end
@ankane

This comment has been minimized.

Owner

ankane commented Mar 23, 2015

@mklemme if you replace properties.to_json with properties, the error should go away. Rails handles the serialization, so it expects hash instead of a string. to_json generates a string.

@mklemme

This comment has been minimized.

mklemme commented Mar 24, 2015

Awesome. It also looks like I had serialization in my model file from an example on here. Removed it and it worked.

@mklemme mklemme closed this Mar 24, 2015

@marckohlbrugge

This comment has been minimized.

marckohlbrugge commented Dec 3, 2015

I ran into the same problem. When running the generator it ignored the -d flag for some reason leading to some unexpected behavior.

@mklemme

This comment has been minimized.

mklemme commented Dec 4, 2015

@marckohlbrugge What was the error?

@marckohlbrugge

This comment has been minimized.

marckohlbrugge commented Dec 4, 2015

@marckohlbrugge Same error as you: TypeError: no implicit conversion of Hash into String. When running the ahoy generators the -d was ignored resulting in the serialize call in the Event model.

@mklemme

This comment has been minimized.

mklemme commented Dec 7, 2015

@marckohlbrugge I copied the custom initializer when I installed it. Might be worth doing that then building anything custom from there? The Active record default init: https://github.com/ankane/ahoy/blob/master/lib/ahoy/stores/active_record_store.rb

@marckohlbrugge

This comment has been minimized.

marckohlbrugge commented Dec 8, 2015

@mklemme Thanks! Don't have a need to customise any of this right now, but will keep it in mind.

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