-
Notifications
You must be signed in to change notification settings - Fork 288
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
1 parent
5bf3996
commit c5c5073
Showing
6 changed files
with
175 additions
and
2 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./sendAnalyticsEvent"; |
77 changes: 77 additions & 0 deletions
77
cdp-agentkit-core/typescript/src/analytics/sendAnalyticsEvent.ts
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,77 @@ | ||
import md5 from "md5"; | ||
|
||
/** | ||
* The required data for an analytics event | ||
* | ||
* Accepts arbitrary additional fields | ||
*/ | ||
type RequiredEventData = { | ||
/** | ||
* The event that took place, e.g. initialize_wallet_provider, agent_action_invocation | ||
*/ | ||
action: string; | ||
/** | ||
* The component that the event took place in, e.g. wallet_provider, agent_action | ||
*/ | ||
component: string; | ||
/** | ||
* The name of the event. This should match the name in AEC | ||
*/ | ||
name: string; | ||
/** | ||
* The timestamp of the event. If not provided, the current time will be used. | ||
*/ | ||
timestamp?: number; | ||
} & Record<string, string | undefined>; | ||
|
||
/** | ||
* Sends an analytics event to the default endpoint | ||
* | ||
* @param event - The event data containing required action, component and name fields | ||
* @returns Promise that resolves when the event is sent | ||
*/ | ||
export async function sendAnalyticsEvent(event: RequiredEventData): Promise<void> { | ||
const timestamp = event.timestamp || Date.now(); | ||
|
||
// Prepare the event with required fields | ||
const enhancedEvent = { | ||
event_type: event.name, | ||
platform: "server", | ||
event_properties: { | ||
component_type: event.component, | ||
platform: "server", | ||
project_name: "agentkit", | ||
time_start: timestamp, | ||
...event, | ||
}, | ||
}; | ||
|
||
const events = [enhancedEvent]; | ||
const stringifiedEventData = JSON.stringify(events); | ||
const uploadTime = timestamp.toString(); | ||
|
||
// Calculate checksum inline | ||
const checksum = md5(stringifiedEventData + uploadTime); | ||
|
||
const analyticsServiceData = { | ||
e: stringifiedEventData, | ||
checksum, | ||
}; | ||
|
||
const apiEndpoint = "https://cca-lite.coinbase.com"; | ||
const eventPath = "/amp"; | ||
const eventEndPoint = `${apiEndpoint}${eventPath}`; | ||
|
||
const response = await fetch(eventEndPoint, { | ||
method: "POST", | ||
mode: "no-cors", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify(analyticsServiceData), | ||
}); | ||
|
||
if (!response.ok) { | ||
throw new Error(`HTTP error! status: ${response.status}`); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
cdp-agentkit-core/typescript/src/wallet_providers/wallet_provider.ts
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.