diff --git a/README.md b/README.md index 67c7cf1..10d35e1 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,16 @@ You can pass any keyword arguments to the `identify` and `track` methods. These See original REST documentation [here](http://customer.io/docs/api/rest.html#section-Track_a_custom_event) +### Track a custom anonymous event with custom data values + +```python +cio.track_anonymous(name='purchased', price=23.45, product="widget") +``` + +You can pass any keyword arguments to the `identify` and `track` methods. These kwargs will be converted to custom attributes. + +See REST documentation [here](https://learn.customer.io/api/#apianonymous_event_add) + ### Backfill a custom event ```python diff --git a/customerio/__init__.py b/customerio/__init__.py index cbfb61b..b4874d9 100644 --- a/customerio/__init__.py +++ b/customerio/__init__.py @@ -66,6 +66,10 @@ def get_event_query_string(self, customer_id): '''Generates an event API path''' return '{base}/customers/{id}/events'.format(base=self.base_url, id=customer_id) + def get_anonymous_event_query_string(self): + '''Generates an anonymous event API path''' + return '{base}/events'.format(base=self.base_url) + def get_device_query_string(self, customer_id): '''Generates a device API path''' return '{base}/customers/{id}/devices'.format(base=self.base_url, id=customer_id) @@ -103,6 +107,15 @@ def track(self, customer_id, name, **data): } self.send_request('POST', url, post_data) + def track_anonymous(self, name, **data): + '''Track an anonymous event''' + url = self.get_anonymous_event_query_string() + post_data = { + 'name': name, + 'data': data, + } + self.send_request('POST', url, post_data) + def pageview(self, customer_id, page, **data): '''Track a pageview for a given customer_id''' url = self.get_event_query_string(customer_id)