Skip to content

Commit

Permalink
Add _strip_empty_properties to session prop storage
Browse files Browse the repository at this point in the history
  • Loading branch information
robbie-c committed Nov 21, 2023
1 parent 7a8b09f commit 88940d8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
13 changes: 8 additions & 5 deletions src/session-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { _info } from './utils/event-utils'
import { SessionIdManager } from './sessionid'
import { PostHogPersistence } from './posthog-persistence'
import { CLIENT_SESSION_PROPS } from './constants'
import { _strip_empty_properties } from './utils'

// this might be stored in a cookie with a hard 4096 byte limit, so save characters on key names
interface SessionSourceProps {
Expand All @@ -33,11 +34,13 @@ export const generateSessionSourceParams = (): SessionSourceProps => {
return {
p: window?.location.pathname || '',
r: _info.referringDomain(),
m: campaignParams.utm_medium,
s: campaignParams.utm_source,
c: campaignParams.utm_campaign,
n: campaignParams.utm_content,
t: campaignParams.utm_term,
..._strip_empty_properties({
m: campaignParams.utm_medium,
s: campaignParams.utm_source,
c: campaignParams.utm_campaign,
n: campaignParams.utm_content,
t: campaignParams.utm_term,
}),
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,11 @@ export const _safewrap_instance_methods = function (obj: Record<string, any>): v
}
}

export const _strip_empty_properties = function (p: Properties): Properties {
const ret: Properties = {}
export const _strip_empty_properties = function <T extends Record<string, any>>(p: T): { [k in keyof T]?: T[k] } {
const ret: Partial<T> = {}
_each(p, function (v, k) {
if (_isString(v) && v.length > 0) {
ret[k] = v
;(ret as any)[k] = v
}
})
return ret
Expand Down

0 comments on commit 88940d8

Please sign in to comment.