-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
35 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
"""Amplitude handler for tracking after env has been set up with a singleton object.""" | ||
import os | ||
|
||
from amplitude import Amplitude, BaseEvent | ||
|
||
|
||
class AmplitudeHandler: | ||
"""Class to handle amplitude events. | ||
Attributes: | ||
_client (Amplitude | None): amplitude client singleton object. | ||
""" | ||
|
||
_client = None | ||
|
||
def track(self, event: BaseEvent): | ||
"""Track an amplitude event. | ||
Args: | ||
event (BaseEvent): the event to track. | ||
""" | ||
if "AMPLITUDE_API_KEY" in os.environ: | ||
if self._client is None: | ||
self._client = Amplitude(os.environ["AMPLITUDE_API_KEY"]) | ||
self._client.track(event) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters