customerio / go-customerio

Official Golang client for the Customer.io API
https://customer.io/docs/api/
MIT License
26 stars 23 forks source link

No way to send anonymous events #5

Closed mgirouard closed 6 years ago

mgirouard commented 6 years ago

I have an app which relies on anonymous events for a significant portion of events we send. It seems as this isn't supported by the Go client, but is in other clients (eg: ruby).

What do you all think about adding a similar method to the CustomerIO struct?

// Track sends a single event to Customer.io for the anonymous user
func (c *CustomerIO) TrackAnonymous(recipientEmail string, eventName string, data map[string]interface{}) error

Happy to PR something like this if it's helpful.

mgirouard commented 6 years ago

Can I get some feedback on this? If there's a better approach I'd be happy to go that direction.

hownowstephen commented 6 years ago

Thanks for the PR, Michael! Only note I have here is that the recipientEmail field shouldn't be a requirement for anonymous events, note the signature of the ruby analog.

While we have special handling for a recipient field if present, you could equally create a campaign for which the "To" field is set to something custom like {{ event.email_address }} (also because of our support for non-email delivery types, the recipient may not be an email address!)

Aside from that, the rest looks 👍 for merging - I'll have someone from the team take a look at getting an updated version rolled out this week

mgirouard commented 6 years ago

Ah ha! That makes it clear. I had misunderstood how anonymous events work and based it off of the Anonymous Invite Emails article with too much focus on the recipient field.

I'll have an updated patch later today!

mgirouard commented 6 years ago

@hownowstephen Finally circling back on this. The signature is simplified now to just the event name and the attributes. Tests pass and I can confirm I see the events coming through in our environment.

Let me know if this works for you.

mgirouard commented 6 years ago

Any chance we can get this merged today? We're using my fork on a project and this is pretty much the last item on our list to close out the project.

Let me know if you need me to jump on anything!

hownowstephen commented 6 years ago

Looks great, thanks for tackling that!

mgirouard commented 6 years ago

Thank you!