Skip to content
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

Track anonymous events #42

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions customerio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down