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

Add support for bulk track/engage APIs #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

mbuhot
Copy link

@mbuhot mbuhot commented Oct 24, 2016

  • Mixpanel.engage function added to update user profile
  • Mixpanel.track and Mixpanel.engage will both support a list of maps
  • When given a list, these functions expect the maps to conform to the structure defined by
    the mixpanel HTTP api documentation (linked from README)

 - `Mixpanel.engage` function added to update user profile
 - `Mixpanel.track` and `Mixpanel.engage` will both support a list of maps
 - When given a list, these functions expect the maps to conform to the structure defined by
    the mixpanel HTTP api documentation (linked from README)
Copy link
Owner

@michihuber michihuber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Mike!

Thank you very much for the pull request!
I added some comments, mostly cosmetics, but I also think we should add some tests using ExVcr (which I should have done from the beginning, my bad).

If you want me to help out with the testing part, please let me know.

Thank you very much!

:ok
end

def engage(event) when is_map(event) do
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both engage fns have the same body, could you collapse them into a single fn, please?

GenServer.cast(:mixpanel_client, {:track, events})
end

def engage(event) when is_map(event) do
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These could also be the same fn.

def handle_cast({:track, event, properties}, state) do
properties = Dict.put(properties, :token, state.token)
{:ok, json} = JSX.encode([event: event, properties: properties])
body = String.to_char_list("data=#{ :base64.encode(json) }")
{:ok, json} = JSX.encode(event: event, properties: properties)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does bulk posting a non-array work?
We should probably add some ex-vcr specs at this point.


def handle_cast({:track, events}, state) when is_list(events) do
events = Enum.map(events, &put_in(&1, [:properties, :token], state.token))
{:ok, json} = JSX.encode(events)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you dry up the encode/post/reply dance that's happening in all the handle_casts, please?

Mike Buhot added 2 commits November 5, 2016 20:46
 - Mixpanel.Client now only accepts lists of events
 - Mixpanel facade normalizes single events to lists of maps
 - Note that these don't actually contain any asserts
 - And the ExVCR integration isn't working
 -- AFAICT the HTTPC adapter doesn't work with a custom :inets profile
 -- Even when using the default profile, the Mixpanel API is async, so need to wait in tests before asserting somehow
@mbuhot
Copy link
Author

mbuhot commented Nov 5, 2016

Hey Michi, thanks for considering this PR.

I've tried to DRY up the implementation as per your feedback.
The Mixpanel module converts single events to lists and Mixpanel.Client only deals in lists of maps.

I didn't have much luck with ExVCR.
The only way I could get it to record was to change GenServer.cast to GenServer.call and to use :httpc.request/4 instead of :httpc.request/5 in Mixpanel.Client

I've added the mix dependency and left the test module in there, but it just exercises the code without actually asserting on anything right now.

@mbuhot
Copy link
Author

mbuhot commented Feb 19, 2017

@michihuber Any suggestions on getting the VCRs on this one working?

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

Successfully merging this pull request may close these issues.

2 participants