Skip to content

Commit

Permalink
feat: stricter useTrackEvent param types
Browse files Browse the repository at this point in the history
fixes #28
  • Loading branch information
johannschopplich committed Sep 15, 2023
1 parent a94ee63 commit d57cbd5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@ Track your defined goals by passing the following parameters:

```ts
function useTrackEvent(
eventName: string,
eventParams?: Record<string, any>
eventName: EventNames | (string & Record<never, never>),
eventParams?: ControlParams | EventParams | Record<string, any>,
): void
```

Expand Down
5 changes: 3 additions & 2 deletions src/runtime/composables/useTrackEvent.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { ControlParams, EventNames, EventParams } from '../types'
import { useGtag } from './useGtag'

export function useTrackEvent(
eventName: string,
eventParams?: Record<string, any>,
eventName: EventNames | (string & Record<never, never>),
eventParams?: ControlParams | EventParams | Record<string, any>,
) {
const { gtag } = useGtag()
gtag('event', eventName, eventParams)
Expand Down
8 changes: 4 additions & 4 deletions src/runtime/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@ export interface Gtag {
(command: 'consent', consentArg: ConsentArg | string, consentParams: ConsentParams): void
}

interface ConfigParams {
export interface ConfigParams {
page_title?: string
page_location?: string
page_path?: string
send_page_view?: boolean
}

interface ControlParams {
export interface ControlParams {
groups?: string | string[]
send_to?: string | string[]
event_callback?: () => void
event_timeout?: number
}

type EventNames =
export type EventNames =
| 'add_payment_info'
| 'add_shipping_info'
| 'add_to_cart'
Expand Down Expand Up @@ -75,7 +75,7 @@ type EventNames =
| 'view_promotion'
| 'view_search_results'

interface EventParams {
export interface EventParams {
checkout_option?: string
checkout_step?: number
content_id?: string
Expand Down

0 comments on commit d57cbd5

Please sign in to comment.