@posthog/core 1.54.5 → 1.55.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/error-tracking/coercers/dom-exception-coercer.d.ts.map +1 -1
- package/dist/error-tracking/coercers/error-coercer.d.ts.map +1 -1
- package/dist/error-tracking/coercers/error-event-coercer.d.ts.map +1 -1
- package/dist/error-tracking/coercers/event-coercer.d.ts.map +1 -1
- package/dist/error-tracking/coercers/object-coercer.d.ts.map +1 -1
- package/dist/error-tracking/coercers/primitive-coercer.d.ts.map +1 -1
- package/dist/error-tracking/coercers/promise-rejection-event.d.ts.map +1 -1
- package/dist/error-tracking/coercers/string-coercer.d.ts.map +1 -1
- package/dist/error-tracking/error-properties-builder.d.ts.map +1 -1
- package/dist/error-tracking/exception-steps.d.ts +2 -2
- package/dist/error-tracking/exception-steps.d.ts.map +1 -1
- package/dist/error-tracking/parsers/safari.d.ts.map +1 -1
- package/dist/error-tracking/types.d.ts +1 -1
- package/dist/error-tracking/types.d.ts.map +1 -1
- package/dist/error-tracking/utils.d.ts.map +1 -1
- package/dist/eventemitter.d.ts.map +1 -1
- package/dist/featureFlagLocalEvaluation.d.ts.map +1 -1
- package/dist/featureFlagUtils.d.ts +5 -5
- package/dist/featureFlagUtils.d.ts.map +1 -1
- package/dist/gzip.d.ts.map +1 -1
- package/dist/logs/index.d.ts.map +1 -1
- package/dist/metrics/index.d.ts.map +1 -1
- package/dist/posthog-core-stateless.d.ts.map +1 -1
- package/dist/posthog-core.d.ts.map +1 -1
- package/dist/surveys/events.d.ts +16 -0
- package/dist/surveys/events.d.ts.map +1 -1
- package/dist/surveys/events.js +34 -0
- package/dist/surveys/events.mjs +29 -1
- package/dist/surveys/index.d.ts +1 -1
- package/dist/surveys/index.d.ts.map +1 -1
- package/dist/surveys/index.js +6 -0
- package/dist/surveys/index.mjs +1 -1
- package/dist/surveys/property-matching.d.ts.map +1 -1
- package/dist/surveys/shuffling.d.ts +1 -1
- package/dist/surveys/shuffling.d.ts.map +1 -1
- package/dist/surveys/translations.d.ts +1 -1
- package/dist/surveys/translations.d.ts.map +1 -1
- package/dist/testing/PostHogCoreTestClient.d.ts.map +1 -1
- package/dist/testing/test-utils.d.ts.map +1 -1
- package/dist/traces/context.d.ts.map +1 -1
- package/dist/traces/index.d.ts.map +1 -1
- package/dist/traces/span.d.ts.map +1 -1
- package/dist/tracing-headers.d.ts.map +1 -1
- package/dist/types.d.ts +53 -51
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -0
- package/dist/types.mjs +1 -0
- package/dist/utils/bot-detection.d.ts.map +1 -1
- package/dist/utils/bucketed-rate-limiter.d.ts.map +1 -1
- package/dist/utils/flush-timer.d.ts.map +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/promise-queue.d.ts.map +1 -1
- package/dist/utils/retry-after.d.ts.map +1 -1
- package/dist/utils/string-utils.d.ts.map +1 -1
- package/dist/utils/type-utils.d.ts.map +1 -1
- package/dist/utils/user-agent-utils.d.ts.map +1 -1
- package/dist/vendor/uuidv7.d.ts.map +1 -1
- package/package.json +2 -1
- package/src/surveys/events.spec.ts +90 -0
- package/src/surveys/events.ts +42 -0
- package/src/surveys/index.ts +2 -0
- package/src/types.ts +2 -0
package/src/surveys/events.ts
CHANGED
|
@@ -54,6 +54,48 @@ export function buildSurveyResponseProperties(
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
export function recordSurveyAnswer(
|
|
58
|
+
{ responses, questionSnapshots = {} }: { responses: SurveyResponses; questionSnapshots?: Record<string, string> },
|
|
59
|
+
questionId: string,
|
|
60
|
+
response: SurveyResponseValue,
|
|
61
|
+
question?: SurveyQuestionForResponses
|
|
62
|
+
): { responses: SurveyResponses; questionSnapshots: Record<string, string> } {
|
|
63
|
+
// Snapshot the question text as it appeared to the user right now, so that
|
|
64
|
+
// $survey_questions[].question in sent/dismissed events reflects the language
|
|
65
|
+
// the user saw when they answered, not the language active at event-fire time.
|
|
66
|
+
return {
|
|
67
|
+
responses: { ...responses, [getSurveyResponseKey(questionId)]: response },
|
|
68
|
+
questionSnapshots: question?.id ? { ...questionSnapshots, [question.id]: question.question } : questionSnapshots,
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function buildSurveyResponseEventProperties({
|
|
73
|
+
event,
|
|
74
|
+
survey,
|
|
75
|
+
responses = {},
|
|
76
|
+
submissionId,
|
|
77
|
+
completed,
|
|
78
|
+
surveyLanguage,
|
|
79
|
+
questionSnapshots,
|
|
80
|
+
}: {
|
|
81
|
+
event: 'sent' | 'dismissed' | 'abandoned'
|
|
82
|
+
survey: SurveyForResponses
|
|
83
|
+
responses?: SurveyResponses
|
|
84
|
+
submissionId?: string
|
|
85
|
+
completed?: boolean
|
|
86
|
+
surveyLanguage?: string | null
|
|
87
|
+
questionSnapshots?: Record<string, string>
|
|
88
|
+
}): Record<string, unknown> {
|
|
89
|
+
return {
|
|
90
|
+
...(!isUndefined(submissionId) && { $survey_submission_id: submissionId }),
|
|
91
|
+
...(event === 'sent'
|
|
92
|
+
? !isUndefined(completed) && { $survey_completed: completed }
|
|
93
|
+
: { $survey_partially_completed: surveyHasResponses(responses) }),
|
|
94
|
+
...(surveyLanguage && { [SURVEY_LANGUAGE_PROPERTY]: surveyLanguage }),
|
|
95
|
+
...buildSurveyResponseProperties(responses, survey, questionSnapshots),
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
57
99
|
export function surveyHasResponses(responses: SurveyResponses = {}): boolean {
|
|
58
100
|
return Object.values(responses).some((response) => !isNullish(response))
|
|
59
101
|
}
|
package/src/surveys/index.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { getValidationError, getLengthFromRules, getRequirementsHint } from './validation'
|
|
2
2
|
export {
|
|
3
3
|
buildSurveyResponseProperties,
|
|
4
|
+
buildSurveyResponseEventProperties,
|
|
5
|
+
recordSurveyAnswer,
|
|
4
6
|
getSurveyInteractionProperty,
|
|
5
7
|
getSurveyOldResponseKey,
|
|
6
8
|
getSurveyResponseKey,
|
package/src/types.ts
CHANGED
|
@@ -292,6 +292,7 @@ export enum PostHogPersistedProperty {
|
|
|
292
292
|
// Session id for which an event trigger has activated session replay. only used by posthog-react-native
|
|
293
293
|
SessionReplayEventTriggerActivatedSession = 'session_replay_event_trigger_activated_session',
|
|
294
294
|
SurveyLastSeenDate = 'survey_last_seen_date', // only used by posthog-react-native
|
|
295
|
+
SurveysInProgress = 'surveys_in_progress', // only used by posthog-react-native
|
|
295
296
|
SurveysSeen = 'surveys_seen', // only used by posthog-react-native
|
|
296
297
|
Surveys = 'surveys', // only used by posthog-react-native
|
|
297
298
|
RemoteConfig = 'remote_config',
|
|
@@ -912,6 +913,7 @@ export type Survey = {
|
|
|
912
913
|
current_iteration?: number | null
|
|
913
914
|
current_iteration_start_date?: string | null
|
|
914
915
|
schedule?: SurveySchedule | null
|
|
916
|
+
enable_partial_responses?: boolean | null
|
|
915
917
|
}
|
|
916
918
|
|
|
917
919
|
export type SurveyActionType = {
|