-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Expose `track` function to track custom events * Work in feedback Co-Authored-By: Chris <7249920+chriswdmr@users.noreply.github.com> * Check if track function successfully queues events into vaq * Add react tests Co-Authored-By: Chris <7249920+chriswdmr@users.noreply.github.com> * Use eslint disable instead of ts-expect-error for tests * Minor style improvments * Respect `mode` attribute * Refactor reading `mode` * Refactor detectEnvironment * Add tests for development mode * Publish 0.1.7-beta.1 * Fix evaluating the mode; adding tests (#31) * Fix version of tests * Update apps/nextjs/package.json Co-authored-by: Douglas Parsons <dglsparsons@users.noreply.github.com> * Merge branch 'main' into add-custom-events * Update pnpm-lock.yaml * Add missing default exports * Fix default exports * Push beta version * Use `event` instead of `track` inside of `vaq` (#35) The analytics-script listens for `event` and not `track` * Only run when window is defined (#38) * Push package version * Add log when server calls track (#40) * Bump package version for new beta release * Fix lint errors with custom events branch (#52) * Address eslint errors with custom events branch * Make CI workflow run regardless of target branch * Bump package version * Update pnpm-lock.yaml * Revert "Update pnpm-lock.yaml" This reverts commit 024f2c8. * Fix build * Update naming Analytics -> Web Analytics * Fix Development tests * Remove beta badge from banner --------- Co-authored-by: Chris <7249920+chriswdmr@users.noreply.github.com> Co-authored-by: Douglas Parsons <dglsparsons@users.noreply.github.com> Co-authored-by: Douglas Parsons <dglsparsons@gmail.com> Co-authored-by: Timo Lins <me@timo.sh>
- Loading branch information
1 parent
affbbc1
commit 6fd786a
Showing
16 changed files
with
535 additions
and
136 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -1,8 +1,6 @@ | ||
name: ci | ||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
push: | ||
branches: | ||
- main | ||
|
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
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
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 |
---|---|---|
@@ -1,39 +1,84 @@ | ||
import { name, version } from '../package.json'; | ||
import { name as packageName, version } from '../package.json'; | ||
import { initQueue } from './queue'; | ||
import type { AnalyticsProps } from './types'; | ||
import { isBrowser, getMode } from './utils'; | ||
import type { AllowedPropertyValues, AnalyticsProps } from './types'; | ||
import { | ||
isBrowser, | ||
parseProperties, | ||
setMode, | ||
isDevelopment, | ||
isProduction, | ||
} from './utils'; | ||
|
||
export const inject = ( | ||
export function inject( | ||
props: AnalyticsProps = { | ||
debug: true, | ||
}, | ||
): void => { | ||
): void { | ||
if (!isBrowser()) return; | ||
|
||
const mode = getMode(props.mode); | ||
setMode(props.mode); | ||
|
||
initQueue(); | ||
|
||
if (props.beforeSend) { | ||
window.va?.('beforeSend', props.beforeSend); | ||
} | ||
|
||
const src = | ||
mode === 'development' | ||
? 'https://va.vercel-scripts.com/v1/script.debug.js' | ||
: '/_vercel/insights/script.js'; | ||
const src = isDevelopment() | ||
? 'https://va.vercel-scripts.com/v1/script.debug.js' | ||
: '/_vercel/insights/script.js'; | ||
|
||
if (document.head.querySelector(`script[src*="${src}"]`)) return; | ||
|
||
const script = document.createElement('script'); | ||
script.src = src; | ||
script.defer = true; | ||
script.setAttribute('data-sdkn', name); | ||
script.setAttribute('data-sdkn', packageName); | ||
script.setAttribute('data-sdkv', version); | ||
|
||
if (mode === 'development' && props.debug === false) { | ||
if (isDevelopment() && props.debug === false) { | ||
script.setAttribute('data-debug', 'false'); | ||
} | ||
|
||
document.head.appendChild(script); | ||
} | ||
|
||
export function track( | ||
name: string, | ||
properties?: Record<string, AllowedPropertyValues>, | ||
): void { | ||
if (!isBrowser()) { | ||
// eslint-disable-next-line no-console | ||
console.warn( | ||
'[Vercel Web Analytics] Server-side execution of `track()` is currently not supported.', | ||
); | ||
return; | ||
} | ||
|
||
if (!properties) { | ||
window.va?.('event', { name }); | ||
return; | ||
} | ||
|
||
try { | ||
const props = parseProperties(properties, { | ||
strip: isProduction(), | ||
}); | ||
|
||
window.va?.('event', { | ||
name, | ||
data: props, | ||
}); | ||
} catch (err) { | ||
if (err instanceof Error && isDevelopment()) { | ||
// eslint-disable-next-line no-console | ||
console.error(err); | ||
} | ||
} | ||
} | ||
|
||
// eslint-disable-next-line import/no-default-export | ||
export default { | ||
inject, | ||
track, | ||
}; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.