Skip to content

Add support for bulk track/engage APIs#3

Open
mbuhot wants to merge 3 commits into
michihuber:masterfrom
everydayhero:bulk-operations
Open

Add support for bulk track/engage APIs#3
mbuhot wants to merge 3 commits into
michihuber:masterfrom
everydayhero:bulk-operations

Conversation

@mbuhot

@mbuhot mbuhot commented Oct 24, 2016

Copy link
Copy Markdown
  • 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)

@michihuber michihuber left a comment

Copy link
Copy Markdown
Owner

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!

Comment thread lib/mixpanel.ex
:ok
end

def engage(event) when is_map(event) do

Copy link
Copy Markdown
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?

Comment thread lib/mixpanel/client.ex Outdated
GenServer.cast(:mixpanel_client, {:track, events})
end

def engage(event) when is_map(event) do

Copy link
Copy Markdown
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.

Comment thread lib/mixpanel/client.ex Outdated
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
Copy Markdown
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.

Comment thread lib/mixpanel/client.ex Outdated

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
Copy Markdown
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

mbuhot commented Nov 5, 2016

Copy link
Copy Markdown
Author

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

mbuhot commented Feb 19, 2017

Copy link
Copy Markdown
Author

@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