From c2785a849dfebb49ed1e410c31b93ceeb3683be7 Mon Sep 17 00:00:00 2001 From: rollerbrick Date: Tue, 22 May 2018 14:39:14 -0700 Subject: [PATCH 1/2] Added tracking of anonymous events. --- README.md | 10 ++++++++++ customerio/__init__.py | 13 +++++++++++++ 2 files changed, 23 insertions(+) diff --git a/README.md b/README.md index 67c7cf1..fbcd063 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 an 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) From 5529f837c9e082cc88a1b856b60a7bcb61535c0d Mon Sep 17 00:00:00 2001 From: rollerbrick Date: Tue, 22 May 2018 14:41:14 -0700 Subject: [PATCH 2/2] Updated Readme. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fbcd063..10d35e1 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ 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 an custom anonymous event with custom data values +### Track a custom anonymous event with custom data values ```python cio.track_anonymous(name='purchased', price=23.45, product="widget")