-
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.
fix: move references to amplitude key to after .env loading (#177)
- Loading branch information
Showing
3 changed files
with
40 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,30 @@ | ||
"""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 __new__(cls): | ||
"""Create a new amplitude handler if one doesn't exist.""" | ||
if "AMPLITUDE_API_KEY" in os.environ: | ||
if cls._client is None: | ||
cls._client = Amplitude(os.environ["AMPLITUDE_API_KEY"]) | ||
return cls._client | ||
|
||
def track(self, event: BaseEvent): | ||
"""Track an amplitude event. | ||
Args: | ||
event (BaseEvent): the event to track. | ||
""" | ||
if self._client is not None: | ||
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