Skip to content

Commit

Permalink
Merge branch 'main' into nm/handle-trial-end
Browse files Browse the repository at this point in the history
  • Loading branch information
meln1k authored Apr 3, 2024
2 parents 8648c36 + 28f9794 commit f28f6db
Show file tree
Hide file tree
Showing 5 changed files with 404 additions and 403 deletions.
4 changes: 4 additions & 0 deletions fixbackend/analytics/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import logging
from base64 import b64decode

from fastapi import APIRouter, Response
Expand All @@ -20,15 +21,18 @@
from fixbackend.dependencies import FixDependencies, ServiceNames
from fixbackend.ids import UserId


# 1x1 transparent PNG pixel
pxl_base64 = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR4nGNgYGBgAAAABQABpfZFQAAAAABJRU5ErkJggg=="
log = logging.getLogger(__name__)


def analytics_router(dependencies: FixDependencies) -> APIRouter:
router = APIRouter()

@router.get("/analytics/email_opened/pixel", include_in_schema=False)
async def email_opened(user: UserId, email: str) -> Response:
log.info(f"Email opened by {user} for email {email}")
sender = dependencies.service(ServiceNames.analytics_event_sender, AnalyticsEventSender) # type: ignore
await sender.send(AEEmailOpened(user_id=user, email=email))
return Response(content=b64decode(pxl_base64), media_type="image/png")
Expand Down
3 changes: 2 additions & 1 deletion fixbackend/notification/email/email_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from functools import lru_cache

from fixbackend.ids import CloudAccountId, WorkspaceId
from fixbackend.utils import uid

TemplatesPath = Path(__file__).parent / "templates"

Expand All @@ -31,7 +32,7 @@ def get_env() -> Environment:

def render(template_name: str, **kwargs: Any) -> str:
template = get_env().get_template(template_name)
result = template.render({"template_name": template_name, **kwargs})
result = template.render({"template_name": template_name, "uid": str(uid()), **kwargs})
return result


Expand Down
2 changes: 1 addition & 1 deletion fixbackend/notification/email/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@
{% if user_id is defined %}
<tr>
<td class="email-masthead" align="center">
<img src="https://app.fix.security/api/analytics/email_opened/pixel?user={{ user_id }}&email={{ template_name }}" alt="" width="1" height="1"/>
<img src="https://app.fix.security/api/analytics/email_opened/pixel?user={{ user_id }}&email={{ template_name }}&uid={{ uid }}" alt="" width="1" height="1"/>
</td>
</tr>
{% endif %}
Expand Down
Loading

0 comments on commit f28f6db

Please sign in to comment.