Sends the current event to Diffgram's EventHub for anonymous data tracking. :return:
(self)
| 331 | |
| 332 | |
| 333 | def send_to_eventhub(self): |
| 334 | """ |
| 335 | Sends the current event to Diffgram's EventHub for anonymous data tracking. |
| 336 | :return: |
| 337 | """ |
| 338 | from shared.settings import settings |
| 339 | EXCLUDED_EVENTHUB_TRACKING_EVENTS = ['user_visit'] |
| 340 | if settings.DIFFGRAM_SYSTEM_MODE in ['testing', 'testing_e2e']: |
| 341 | return |
| 342 | |
| 343 | if settings.DIFFGRAM_SYSTEM_MODE in ['sandbox'] and self.kind in EXCLUDED_EVENTHUB_TRACKING_EVENTS: |
| 344 | return |
| 345 | |
| 346 | if settings.ALLOW_EVENTHUB is False: |
| 347 | return |
| 348 | |
| 349 | try: |
| 350 | event_data = self.serialize() |
| 351 | event_data['event_type'] = 'user' |
| 352 | event_data['install_fingerprint'] = settings.DIFFGRAM_INSTALL_FINGERPRINT |
| 353 | result = requests.post(settings.EVENTHUB_URL, json = event_data, timeout = 3) |
| 354 | if result.status_code == 200: |
| 355 | logger.debug(f"Sent event: {self.id} to Diffgram Eventhub") |
| 356 | else: |
| 357 | logger.error( |
| 358 | f"Error sending ID: {self.id} to Eventhub. Status Code: {result.status_code}. result.text: {result.text}") |
| 359 | except Exception as e: |
| 360 | logger.error(f"Exception sending {str(e)} to Diffgram Eventhub: ") |
| 361 | |
| 362 | @staticmethod |
| 363 | def identify_user(user): |