-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add custom pageview property support #16
base: develop
Are you sure you want to change the base?
feat: add custom pageview property support #16
Conversation
- adds `pageview-props` script src segment - adds various types and guards for Plausible-enforced property limits - defends against `svelte-preprocess` [issue with shorthand `{src}` attribute](sveltejs/svelte-preprocess#604) (accuser#12) - updates README - updates configuration/npm scripts for prettier@3
$: api = `${apiHost}/api/event`; | ||
$: src = [ | ||
$: plausibleSrc = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#12 identified an issue with svelte-preprocess
and the shorthand {src}
data-api={api} | ||
data-domain={domain.toString()} | ||
defer | ||
src={plausibleSrc} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#12 identified an issue with svelte-preprocess
and the shorthand {src}
@dgrebb any chance you will continue on this? |
@till absolutely - did you have any feedback on he guards I added? I have a few more moths of TS under my belt and will take a gander. With Svelte 5 on the way, I may change approach as well. I'll take a look this week. |
Summary
This adds support for custom properties in pageview events. Plausible sets limits on number and length, and this includes type guards and warnings in
dev
mode.The history was a bit messy, so I've recreated it from current upstream
develop
. Downstreamdevelop
is up to date, if you want to pull that in.Details
pageview-props
script src segmentsvelte-preprocess
issue with shorthand{src}
attribute (Support SvelteKit 2 #12)The guards feel a bit too much — I'm curious if there is a more efficient, concise, Typescriptier way to do this.
isCustomPropsLimit
: warns if passing more than 30 propertiesisCustomPropEntryLimit
: warns if a custom prop entry is more thanlimit
characters (300 and 2000 for key/value respectively)handleEntry
: warns if a property value is aDOM
interfaceAdded some documentation for the component prop:
I'd be happy to dial the guards back and use some nested ternaries instead, but I think there may be some value in
handleEntry
, a helper insrc/lib/guards.ts
.It checks if any DOM instances have been passed as a property value, like a
DOMTokenList
,HTMLInputElement
, etc.I can also add a new route and tests for coverage. Let me know what you think!