-
Notifications
You must be signed in to change notification settings - Fork 2
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
base: master
Are you sure you want to change the base?
Conversation
- `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)
There was a problem hiding this 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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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_cast
s, please?
- 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
Hey Michi, thanks for considering this PR. I've tried to DRY up the implementation as per your feedback. I didn't have much luck with ExVCR. 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. |
@michihuber Any suggestions on getting the VCRs on this one working? |
Mixpanel.engage
function added to update user profileMixpanel.track
andMixpanel.engage
will both support a list of mapsthe mixpanel HTTP api documentation (linked from README)