From 10f955fd0aeaaf3a106092c5ec2364e57a384af8 Mon Sep 17 00:00:00 2001 From: Samrat Sahoo Date: Tue, 5 Mar 2024 00:49:07 -0500 Subject: [PATCH] fix: refine queries, endpoints, etc. --- README.md | 8 ++++-- api/Dockerfile.dev | 2 +- api/src/actions/click-event.ts | 4 +-- api/src/actions/custom-event-type.ts | 22 ++++++++------- api/src/actions/custom-event.ts | 17 ++++++----- api/src/actions/custom-graph-type.ts | 28 +++++++++---------- api/src/actions/input-event.ts | 4 +-- api/src/actions/project.ts | 2 +- api/src/actions/visit-event.ts | 4 +-- .../controllers/events/custom-event-type.ts | 16 +++++++---- api/src/controllers/events/custom-event.ts | 24 ++++++++++------ api/src/controllers/events/visit-event.ts | 1 - .../controllers/graphs/custom-graph-type.ts | 17 +++++------ api/src/models/base-event.ts | 4 +-- api/src/models/custom-event.ts | 4 +-- api/src/models/custom-graph-type.ts | 8 ++---- api/src/models/visit-event.ts | 4 --- api/src/utils/types.ts | 13 +++++++-- dashboard/scripts/data.py | 14 +++++----- dashboard/widgets/visit_event_widgets.py | 7 ++--- package/src/actions/visit-event.ts | 3 +- package/src/lib/analytics-logger.ts | 6 ++-- 22 files changed, 111 insertions(+), 101 deletions(-) diff --git a/README.md b/README.md index e935392..dbc91a6 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ We define a couple of different event types that are unified across Bits of Good "ObjectId": "id of the object (i.e. a specific button, tab, etc.) that was clicked", "UserId": "id of the user who clicked said event" } + "Created At": "Date the event was created at" } ``` - Visit Events: These are events that occur when a user visits a specific page in an application (i.e. a user visits `/app` or `/home`) @@ -31,8 +32,8 @@ We define a couple of different event types that are unified across Bits of Good "Event Properties": { "PageUrl": "URL of the page that was visited in the app", "UserId": "user who visited that page", - "Date": "date when they visited a page" - } + }, + "Created At": "Date the event was created at" } ``` - Input Events: These are events where a user inputs a specific piece of information into a input box @@ -44,7 +45,8 @@ We define a couple of different event types that are unified across Bits of Good "ObjectId": "id of the object (i.e. a specific text field) where the user inputted data", "UserId": "id of the user who inputted the text", "TextValue": "value of the text that was submitted into the text field" - } + }, + "Created At": "Date the event was created at" } ``` diff --git a/api/Dockerfile.dev b/api/Dockerfile.dev index 0780dad..c6bf7bc 100644 --- a/api/Dockerfile.dev +++ b/api/Dockerfile.dev @@ -12,4 +12,4 @@ RUN yarn install RUN chmod -R 777 node_modules/ -ENTRYPOINT ["yarn", "dev"] \ No newline at end of file +ENTRYPOINT ["sh", "-c", "rm -rf /tmp/tsx-0 && yarn dev"] \ No newline at end of file diff --git a/api/src/actions/click-event.ts b/api/src/actions/click-event.ts index ad70d2a..7e99bd9 100644 --- a/api/src/actions/click-event.ts +++ b/api/src/actions/click-event.ts @@ -12,7 +12,7 @@ export const createClickEvent = async (event: Partial) => { export const getClickEvents = async (date?: Date) => { await dbConnect(); let fromDate = date ?? new Date(Date.now() - 60 * 60 * 24 * 30 * 1000) - const events = await ClickEventModel.find({ date: { $gte: fromDate } }) + const events = await ClickEventModel.find({ createdAt: { $gte: fromDate } }) return events } @@ -22,7 +22,7 @@ export const paginatedGetClickEvents = async (afterDate: Date, afterID: String, if (project && project._id) { const events = await ClickEventModel.find( { - date: { $gte: afterDate }, + createdAt: { $gte: afterDate }, ...(afterID && { _id: { $gte: afterID } }), projectId: project._id }) diff --git a/api/src/actions/custom-event-type.ts b/api/src/actions/custom-event-type.ts index 5f52634..7cba763 100644 --- a/api/src/actions/custom-event-type.ts +++ b/api/src/actions/custom-event-type.ts @@ -3,15 +3,16 @@ import { dbConnect } from "@/src/utils/db-connect"; import CustomEventTypeModel from "@/src/models/custom-event-type"; import CustomEvent from "@/src/models/custom-event"; import CustomGraphType from "@/src/models/custom-graph-type"; +import { Types } from "mongoose"; +export const findEventForProject = async (projectId: string | Types.ObjectId, category: string, subcategory: string) => { + await dbConnect(); + return await CustomEventTypeModel.findOne({ projectId, category, subcategory }) + +} export const createCustomEventType = async (eventType: Partial) => { await dbConnect(); - let { projectId, category, subcategory } = eventType - let sameEvents = await CustomEventTypeModel.find({ projectId, category, subcategory }) - if (sameEvents != null) { - throw new Error("A custom event type with the same category and subcategory already exists") - } const createdEventType = await CustomEventTypeModel.create(eventType); return createdEventType; } @@ -28,16 +29,17 @@ export const getCustomEventType = async (projectId: string, category: string, su } export const getCustomEventTypeID = async (projectId: string, category: string, subcategory: string) => { await dbConnect(); - const eventType = await CustomEventTypeModel.find({ projectId, category, subcategory }) - return eventType._id; + const eventType = await CustomEventTypeModel.findOne({ projectId, category, subcategory }) + return eventType?._id; } export const deleteCustomEventType = async (projectId: string, category: string, subcategory: string) => { - let deletedEventType = await CustomEventTypeModel.delete({ projectId, category, subcategory }) - if (deletedEventType == null) { + const deletedEventType = await CustomEventTypeModel.findOne({ projectId, category, subcategory }); + if (!deletedEventType) { return; } let eventTypeId = deletedEventType._id - //delete events with this id + await CustomEvent.deleteMany({ eventTypeId }) await CustomGraphType.deleteMany({ eventTypeId }) + await CustomEventTypeModel.deleteOne({ projectId, category, subcategory }) } \ No newline at end of file diff --git a/api/src/actions/custom-event.ts b/api/src/actions/custom-event.ts index 742259b..6ea7266 100644 --- a/api/src/actions/custom-event.ts +++ b/api/src/actions/custom-event.ts @@ -7,26 +7,25 @@ import CustomGraphType from "@/src/models/custom-graph-type"; export const createCustomEvent = async (projectId: string, eventTypeId: string, properties: object) => { await dbConnect(); - let eventType = CustomEventTypeModel.find({ _id: eventTypeId, projectId }) - if (eventType == null) { - //there is no event with this id for this projectId - return; + let eventType = await CustomEventTypeModel.findOne({ _id: eventTypeId, projectId }) + + if (!eventType) { + return null; } - let typeProperties = eventType.properties + let typeProperties = eventType.properties; if (Object.keys(typeProperties).length === Object.keys(properties).length && Object.keys(typeProperties).every(k => properties.hasOwnProperty(k))) { - //Checks if all the properties in event type are in the custom even properties - return; + return null; } const createdEvent = await CustomEvent.create({ projectId, eventTypeId, properties }); return createdEvent; } //one function to get eventTypeId, then this paginated method -export const paginatedGetCustomEvents = async (eventTypeId: string, afterDate: string, afterID: string, limit: number) => { +export const paginatedGetCustomEvents = async (eventTypeId: string, afterDate: Date, afterID: string, limit: number) => { await dbConnect(); const events = await CustomEvent.find( { - date: { $gte: afterDate }, + createdAt: { $gte: afterDate }, ...(afterID && { _id: { $gte: afterID } }), eventTypeId }) diff --git a/api/src/actions/custom-graph-type.ts b/api/src/actions/custom-graph-type.ts index 522ca1b..03d7ec0 100644 --- a/api/src/actions/custom-graph-type.ts +++ b/api/src/actions/custom-graph-type.ts @@ -1,25 +1,23 @@ import { dbConnect } from "@/src/utils/db-connect"; import CustomGraphTypeModel from "@/src/models/custom-event-type"; -import { CustomGraphType } from "@/src/utils/types"; +import { CustomGraphType, GraphTypes } from "@/src/utils/types"; +import CustomEventTypeModel from "@/src/models/custom-event-type"; export const createCustomGraphType = async (newGraph: Partial) => { await dbConnect(); let eventTypeId = newGraph.eventTypeId - let eventType = CustomGraphTypeModel.find({ _id: eventTypeId }) - if (eventType == null) { - //there is no event with this id for this projectId - return; + let eventType = await CustomEventTypeModel.findOne({ _id: eventTypeId }) + if (!eventType) { + return null; } - let typeProperties = eventType.properties - if (!typeProperties.includes("xProperty") || !typeProperties.includes("yProperty")) { - //Checks if all the properties in event type are in the custom even properties - return; + let typeProperties = eventType.properties; + if (!typeProperties.includes(newGraph.xProperty as string) || !typeProperties.includes(newGraph.yProperty as string)) { + return null; } - let type = newGraph.graphType - if (type != "bar" && type != "line" && type != "scatter") { - //graphType is not bar, line, or scatter - return; + + if (!Object.values(GraphTypes).includes(newGraph.graphType as GraphTypes)) { + return null; } const createdGraphType = await CustomGraphTypeModel.create(newGraph); return createdGraphType; @@ -27,11 +25,11 @@ export const createCustomGraphType = async (newGraph: Partial) export const getCustomGraphTypes = async (eventTypeId: string, projectId: string) => { await dbConnect(); - const graphTypes = await CustomGraphTypeModel.find({ eventTypeId, projectId}) + const graphTypes = await CustomGraphTypeModel.find({ eventTypeId, projectId }) return graphTypes } export const deleteCustomGraphType = async (_id: string) => { await dbConnect(); - const deletedGraphType = await CustomGraphTypeModel.deleteOne({_id}) + const deletedGraphType = await CustomGraphTypeModel.deleteOne({ _id }) return deletedGraphType } \ No newline at end of file diff --git a/api/src/actions/input-event.ts b/api/src/actions/input-event.ts index d2727c3..8a2afc6 100644 --- a/api/src/actions/input-event.ts +++ b/api/src/actions/input-event.ts @@ -12,7 +12,7 @@ export const createInputEvent = async (event: Partial) => { export const getInputEvents = async (date?: Date) => { await dbConnect(); const fromDate = date ?? new Date(Date.now() - 60 * 60 * 24 * 30 * 1000) - const events = await InputEventModel.find({ date: { $gte: fromDate } }) + const events = await InputEventModel.find({ createdAt: { $gte: fromDate } }) return events } @@ -22,7 +22,7 @@ export const paginatedGetInputEvents = async (afterDate: Date, afterID: String, if (project && project._id) { const events = await InputEventModel.find( { - date: { $gte: afterDate }, + createdAt: { $gte: afterDate }, ...(afterID && { _id: { $gte: afterID } }), projectId: project._id }) diff --git a/api/src/actions/project.ts b/api/src/actions/project.ts index 2576a3a..f548437 100644 --- a/api/src/actions/project.ts +++ b/api/src/actions/project.ts @@ -11,7 +11,7 @@ export const createProject = async (project: Partial) => { export const getProjectIDByName = async (projectName: string) => { await dbConnect(); const project = await ProjectModel.findOne({ projectName }); - return project._id + return project?._id } export const getProjectByClientKey = async (clientApiKey: string): Promise => { await dbConnect(); diff --git a/api/src/actions/visit-event.ts b/api/src/actions/visit-event.ts index 9f232b9..8c70e6d 100644 --- a/api/src/actions/visit-event.ts +++ b/api/src/actions/visit-event.ts @@ -12,7 +12,7 @@ export const createVisitEvent = async (event: Partial) => { export const getVisitEvents = async (date?: Date) => { await dbConnect(); const fromDate = date ?? new Date(Date.now() - 60 * 60 * 24 * 30 * 1000) - const events = await VisitEventModel.find({ date: { $gte: fromDate } }) + const events = await VisitEventModel.find({ createdAt: { $gte: fromDate } }) return events } export const paginatedGetVisitEvents = async (afterDate: Date, afterID: string, limit: number, projectName: String) => { @@ -22,7 +22,7 @@ export const paginatedGetVisitEvents = async (afterDate: Date, afterID: string, const events = await VisitEventModel.find( { - date: { $gte: afterDate }, + createdAt: { $gte: afterDate }, ...(afterID && { _id: { $gte: afterID } }), projectId: project._id }) diff --git a/api/src/controllers/events/custom-event-type.ts b/api/src/controllers/events/custom-event-type.ts index 4520d3f..5ac6025 100644 --- a/api/src/controllers/events/custom-event-type.ts +++ b/api/src/controllers/events/custom-event-type.ts @@ -1,4 +1,4 @@ -import { createCustomEventType, getCustomEventTypesForProject, deleteCustomEventType } from "@/src/actions/custom-event-type"; +import { createCustomEventType, getCustomEventTypesForProject, deleteCustomEventType, findEventForProject } from "@/src/actions/custom-event-type"; import { getProjectIDByName } from "@/src/actions/project"; import { getProjectByServerKey } from "@/src/actions/project"; import { relogRequestHandler } from "@/src/middleware/request-middleware"; @@ -28,6 +28,12 @@ const customEventTypeRoute = APIWrapper({ properties: properties, projectId: project._id, } + + const preexistingEventType = await findEventForProject(project._id, category, subcategory) + if (preexistingEventType != null) { + throw new Error("A custom event type with the same category and subcategory already exists") + } + const createdType = await createCustomEventType(customEventType); return createdType; }, @@ -47,7 +53,7 @@ const customEventTypeRoute = APIWrapper({ if (!id) { throw new Error("Project does not exist") } - const types = await getCustomEventTypesForProject(id); + const types = await getCustomEventTypesForProject(id.toString()); return types; }, }, @@ -57,16 +63,16 @@ const customEventTypeRoute = APIWrapper({ requireServerToken: true }, handler: async (req: Request) => { - const {category, subcategory} = req.body + const { category, subcategory } = req.body if (!category || !subcategory) { throw new Error("You must specify a category and subcategory to delete custom event types!") } - const project = await getProjectByServerKey(req.headers.serverToken as string); + const project = await getProjectByServerKey(req.headers.servertoken as string); if (!project) { throw new Error("Project does not exist") } - deleteCustomEventType(project._id, category, subcategory) + await deleteCustomEventType(project._id.toString(), category, subcategory) }, }, diff --git a/api/src/controllers/events/custom-event.ts b/api/src/controllers/events/custom-event.ts index 71d8bed..ea1d32d 100644 --- a/api/src/controllers/events/custom-event.ts +++ b/api/src/controllers/events/custom-event.ts @@ -18,14 +18,18 @@ const customEventRoute = APIWrapper({ if (!eventTypeId || !properties) { throw new Error("You must specify a category and subcategory to create a custom event!") } - const project = await getProjectByClientKey(req.headers.clientToken as string); + const project = await getProjectByClientKey(req.headers.clienttoken as string); if (!project) { throw new Error("Project does not exist for client token") } - const createdType = await createCustomEvent(project._id, eventTypeId, properties); - return createdType; + const createdEvent = await createCustomEvent(project._id.toString(), eventTypeId, properties); + + if (!createdEvent) { + throw new Error("Failed to create custom event"); + } + return createdEvent; }, }, GET: { @@ -43,14 +47,18 @@ const customEventRoute = APIWrapper({ if (!id) { throw new Error("Project does not exist") } - const eventType = await getCustomEventTypeID(id, category as string, subcategory as string) - const { afterId } = req.params; - const limit = req.params.limit ?? 10 - const afterTime = req.params.afterTime ?? new Date(Date.now() - 60 * 60 * 24 * 30 * 1000) + const eventType = await getCustomEventTypeID(id.toString(), category as string, subcategory as string); + if (!eventType) { + throw new Error("Event type does not exist"); + } + + const { afterId } = req.query; + const limit = req.query.limit ?? 10 + const afterTime = req.query.afterTime ? new Date(req.query.afterTime as string) : new Date(Date.now() - 60 * 60 * 24 * 30 * 1000) if (!projectName) { throw new Error("You must specify a project name to create a project!") } - let events = await paginatedGetCustomEvents(eventType._id, afterTime, afterId, parseInt(limit)); + let events = await paginatedGetCustomEvents(eventType.toString(), afterTime, afterId as string, parseInt(limit as string)); return events; }, }, diff --git a/api/src/controllers/events/visit-event.ts b/api/src/controllers/events/visit-event.ts index 79eabc6..604f632 100644 --- a/api/src/controllers/events/visit-event.ts +++ b/api/src/controllers/events/visit-event.ts @@ -28,7 +28,6 @@ const visitEventRoute = APIWrapper({ eventProperties: { pageUrl, userId, - date } } diff --git a/api/src/controllers/graphs/custom-graph-type.ts b/api/src/controllers/graphs/custom-graph-type.ts index 1234363..dbb7330 100644 --- a/api/src/controllers/graphs/custom-graph-type.ts +++ b/api/src/controllers/graphs/custom-graph-type.ts @@ -16,7 +16,7 @@ const customGraphTypeRoute = APIWrapper({ if (!eventTypeId || !xProperty || !yProperty || !graphType) { throw new Error("You must specify an event type, x property, y property, and graph type to create a custom graph!") } - const project = await getProjectByClientKey(req.headers.serverToken as string); + const project = await getProjectByClientKey(req.headers.servertoken as string); if (!project) { throw new Error("Project does not exist for client token") @@ -27,16 +27,14 @@ const customGraphTypeRoute = APIWrapper({ xProperty, yProperty, graphType, - - } - if (req.body.caption !== undefined) { - graphType.graphType = { - ...graphType.graphType, - caption: req.body.caption, - }; - } + ...(req.body.caption !== undefined && { graphType: { ...graphType, caption: req.body.caption } }) + }; const createdGraphType = await createCustomGraphType(customGraphType); + + if (!createdGraphType) { + throw new Error("Failed to create a custom graph"); + } return createdGraphType; }, }, @@ -65,7 +63,6 @@ const customGraphTypeRoute = APIWrapper({ if (!projectId || !eventTypeId) { throw new Error("You must specify a project and event type to get custom event types!") } - //api wrapper will check that server token is valid let graphTypes = await getCustomGraphTypes(eventTypeId, projectId); return graphTypes; }, diff --git a/api/src/models/base-event.ts b/api/src/models/base-event.ts index 5e736f7..257cc08 100644 --- a/api/src/models/base-event.ts +++ b/api/src/models/base-event.ts @@ -16,10 +16,10 @@ export const BaseEventSchema = new mongoose.Schema({ required: true, ref: ProjectModel.modelName } -}); +}, { timestamps: true }); const BaseEventModel = (mongoose.models.BaseEvent as mongoose.Model) || mongoose.model("BaseEvent", BaseEventSchema); -export default BaseEventModel; \ No newline at end of file +export default BaseEventModel; diff --git a/api/src/models/custom-event.ts b/api/src/models/custom-event.ts index 302b885..f9e1d1e 100644 --- a/api/src/models/custom-event.ts +++ b/api/src/models/custom-event.ts @@ -22,10 +22,10 @@ export const CustomEventSchema = new mongoose.Schema({ required: true, ref: CustomEventTypeModel.modelName } -}); +}, { timestamps: true }); const CustomEventModel = (mongoose.models.CustomEvent as mongoose.Model) || - mongoose.model("CustomEvent", CustomEvent); + mongoose.model("CustomEvent", CustomEventSchema); export default CustomEventModel; \ No newline at end of file diff --git a/api/src/models/custom-graph-type.ts b/api/src/models/custom-graph-type.ts index e1c4a69..7bd4408 100644 --- a/api/src/models/custom-graph-type.ts +++ b/api/src/models/custom-graph-type.ts @@ -3,11 +3,7 @@ import { CustomGraphType } from "@/src/utils/types"; import ProjectModel from "@/src/models/project"; import CustomEventTypeModel from "@/src/models/custom-event-type"; -export const CustomEventSchema = new mongoose.Schema({ - subcategory: { - type: String, - required: true, - }, +export const CustomGraphTypeSchema = new mongoose.Schema({ projectId: { type: Schema.Types.ObjectId, required: true, @@ -42,6 +38,6 @@ export const CustomEventSchema = new mongoose.Schema({ const CustomGraphTypeModel = (mongoose.models.CustomGraphType as mongoose.Model) || - mongoose.model("CustomGraphType", CustomGraphType); + mongoose.model("CustomGraphType", CustomGraphTypeSchema); export default CustomGraphTypeModel; \ No newline at end of file diff --git a/api/src/models/visit-event.ts b/api/src/models/visit-event.ts index 2f5155e..2f78ed0 100644 --- a/api/src/models/visit-event.ts +++ b/api/src/models/visit-event.ts @@ -14,10 +14,6 @@ const VisitEventSchema = new Schema; } + export interface CustomGraphType { _id: string | Types.ObjectId; eventTypeId: string | Types.ObjectId; @@ -101,4 +104,10 @@ export enum EventSubcategories { CLICK = "Click", VISIT = "Visit", INPUT = "Input", +} + +export enum GraphTypes { + BAR = "bar", + SCATTER = "scatter", + LINE = "line" } \ No newline at end of file diff --git a/dashboard/scripts/data.py b/dashboard/scripts/data.py index 14fef5b..1ddd62d 100644 --- a/dashboard/scripts/data.py +++ b/dashboard/scripts/data.py @@ -1,19 +1,24 @@ import datetime import random +possible_dates = [ + (datetime.datetime.now() - datetime.timedelta(days=i)).isoformat() + for i in range(30) +] + class BaseEvent: def __init__(self, event_properties, category, subcategory) -> None: self.category = category self.subcategory = subcategory self.event_properties = event_properties + self.createdAt = random.choice(possible_dates) class VisitEventProperties: - def __init__(self, pageUrl, user_id, date) -> None: + def __init__(self, pageUrl, user_id) -> None: self.pageUrl = pageUrl self.user_id = user_id - self.date = date class VisitEvent(BaseEvent): @@ -74,10 +79,6 @@ def __init__(self, category, subcategory, xProperty, yProperty, graphType) -> No possible_inputs = [f"input_{i}" for i in range(0, 5)] possible_users = [f"user_{i}" for i in range(0, 100)] possible_text_values = [f"text_{i}" for i in range(0, 5)] -possible_dates = [ - (datetime.datetime.now() - datetime.timedelta(days=i)).isoformat() - for i in range(30) -] possible_custom_event_categories = [f"custom{i}" for i in range(0, 2)] possible_custom_event_subcategories = [f"custom{i}" for i in range(0, 2)] @@ -93,7 +94,6 @@ def __init__(self, category, subcategory, xProperty, yProperty, graphType) -> No visit_properties = VisitEventProperties( pageUrl=random.choice(possible_urls), user_id=random.choice(possible_users), - date=random.choice(possible_dates), ) visit_events.append(VisitEvent(visit_properties)) diff --git a/dashboard/widgets/visit_event_widgets.py b/dashboard/widgets/visit_event_widgets.py index 5806dc1..6449d23 100644 --- a/dashboard/widgets/visit_event_widgets.py +++ b/dashboard/widgets/visit_event_widgets.py @@ -14,12 +14,12 @@ def init_recent_events_table(st, visit_events): st.markdown(hide_table_row_index, unsafe_allow_html=True) - visit_sorted = sorted(visit_events, key=lambda event: event.event_properties.date) + visit_sorted = sorted(visit_events, key=lambda event: event.createdAt) data = [ { "Page URL": event.event_properties.pageUrl, "User ID": event.event_properties.user_id, - "Date": event.event_properties.date, + "Date": event.createdAt, } for event in visit_sorted ] @@ -90,14 +90,13 @@ def init_page_active_users_graph(st, visit_events): .properties(width=600, height=400) ) - st.altair_chart(chart, use_container_width=True) def init_visitors_over_time_graph(st, visit_events): st.write("**Visitors Over Time Graph**") data = { - "Date": [event.event_properties.date for event in visit_events], + "Date": [event.createdAt for event in visit_events], "pageUrl": [event.event_properties.pageUrl for event in visit_events], "Number of Visitors": [1 for _ in visit_events], } diff --git a/package/src/actions/visit-event.ts b/package/src/actions/visit-event.ts index 39f6813..2c70d7c 100644 --- a/package/src/actions/visit-event.ts +++ b/package/src/actions/visit-event.ts @@ -3,7 +3,7 @@ import { VisitEvent, HttpMethod } from "@/utils/types"; import { urls } from "@/utils/urls" const visitEventUrl = urls.apiBaseUrl + urls.events.visitEvent; -export const createVisitEvent = async (apiKey: string, pageUrl: string, userId: string, date: Date): Promise => { +export const createVisitEvent = async (apiKey: string, pageUrl: string, userId: string): Promise => { return externalRequest({ url: visitEventUrl, method: HttpMethod.POST, @@ -11,7 +11,6 @@ export const createVisitEvent = async (apiKey: string, pageUrl: string, userId: body: { pageUrl, userId, - date } }) } \ No newline at end of file diff --git a/package/src/lib/analytics-logger.ts b/package/src/lib/analytics-logger.ts index ba58559..63275ef 100644 --- a/package/src/lib/analytics-logger.ts +++ b/package/src/lib/analytics-logger.ts @@ -35,14 +35,14 @@ export default class AnalyticsLogger { } } - public async logVisitEvent(pageUrl: string, userId: string, date: Date): Promise { + public async logVisitEvent(pageUrl: string, userId: string): Promise { try { if (!this.clientApiKey) { throw new Error('Please authenticate first with your client api key using the authenticate method'); } // Client side API Key - const event = await createVisitEvent(this.clientApiKey, pageUrl, userId, date); + const event = await createVisitEvent(this.clientApiKey, pageUrl, userId); return event; } catch { @@ -51,7 +51,7 @@ export default class AnalyticsLogger { { clientApiKey: this.clientApiKey as string, pageUrl, - userId, date: date.toString() + userId } )) return null