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

EPR-996 Email SendGrid ClickTracking #24

Merged
merged 4 commits into from
Oct 23, 2023
Merged
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
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ brew services list
```

#### Environment and Dependencies

Install Pipenv (if needed)

```bash
Expand Down Expand Up @@ -161,6 +162,38 @@ You can provide attachments either inline (with the base64-encoded `content` fie
}
```

### Filter: clicktrack

[docs.sendgrid.com](https://docs.sendgrid.com/for-developers/sending-email/smtp-filters#filter-clicktrack)

```json
{
"subject": "Hi Diddly Ho",
"to": [{
"email": "[email protected]",
"name": "Homer Simpson"
}],
"from": {
"email": "[email protected]",
"name": "Ned Flanders"
},
"content": [
{
"type": "text/plain",
"value": "Try search with https://google.com"
}
],
"filters" : {
"clicktrack" : {
"settings" : {
"enable" : 0,
"enable_text" : false
}
}
}
}
```

## Testing

Code coverage command with missing statement line numbers
Expand Down
15 changes: 14 additions & 1 deletion tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import celery
from python_http_client.exceptions import HTTPError
import sendgrid
from sendgrid.helpers.mail import (Mail, From, To, Cc, Bcc, Personalization, Subject, Asm, GroupId, GroupsToDisplay)
from sendgrid.helpers.mail import (Mail, From, To, Cc, Bcc, Personalization, Subject, Asm, GroupId, GroupsToDisplay, TrackingSettings, ClickTracking)
from jinja2 import Environment, BaseLoader
from jinja2.filters import FILTERS, pass_environment
from jinja2.exceptions import TemplateNotFound
Expand Down Expand Up @@ -155,6 +155,19 @@ def generate_message(data):
message.asm = Asm(GroupId(data['asm']['group_id']),
GroupsToDisplay(data['asm']['groups_to_display']))

# https://docs.sendgrid.com/for-developers/sending-email/smtp-filters#filter-clicktrack
if 'filters' in data \
and 'clicktrack' in data['filters'] \
and 'settings' in data['filters']['clicktrack']:

clicktrack_settings = data['filters']['clicktrack']['settings']
clicktrack_enable = bool(clicktrack_settings.get('enable', False))
clicktrack_enable_text = bool(clicktrack_settings.get('enable_text', False))

tracking_settings = TrackingSettings()
tracking_settings.click_tracking = ClickTracking(clicktrack_enable, clicktrack_enable_text)
message.tracking_settings = tracking_settings

func_switcher = {
"content": HelperService.get_content,
"attachments": HelperService.get_attachments,
Expand Down
8 changes: 8 additions & 0 deletions tests/mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@
"asm": {
"group_id": 1,
"groups_to_display": [1, 2]
},
"filters" : {
"clicktrack" : {
"settings" : {
"enable" : 0,
"enable_text" : False
}
}
}
}

Expand Down
Loading