@tellescope/react-components 1.204.1 → 1.204.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tellescope/react-components",
3
- "version": "1.204.1",
3
+ "version": "1.204.2",
4
4
  "description": "",
5
5
  "main": "./lib/cjs/index.js",
6
6
  "module": "./lib/esm/index.js",
@@ -47,13 +47,13 @@
47
47
  "@reduxjs/toolkit": "^1.6.2",
48
48
  "@stripe/react-stripe-js": "^2.9.0",
49
49
  "@stripe/stripe-js": "^1.52.1",
50
- "@tellescope/constants": "^1.204.1",
51
- "@tellescope/sdk": "^1.204.1",
52
- "@tellescope/types-client": "^1.204.1",
53
- "@tellescope/types-models": "^1.204.1",
54
- "@tellescope/types-utilities": "^1.204.1",
55
- "@tellescope/utilities": "^1.204.1",
56
- "@tellescope/validation": "^1.204.1",
50
+ "@tellescope/constants": "^1.204.2",
51
+ "@tellescope/sdk": "^1.204.2",
52
+ "@tellescope/types-client": "^1.204.2",
53
+ "@tellescope/types-models": "^1.204.2",
54
+ "@tellescope/types-utilities": "^1.204.2",
55
+ "@tellescope/utilities": "^1.204.2",
56
+ "@tellescope/validation": "^1.204.2",
57
57
  "@typescript-eslint/eslint-plugin": "^4.33.0",
58
58
  "@typescript-eslint/parser": "^4.33.0",
59
59
  "css-to-react-native": "^3.0.0",
@@ -84,7 +84,7 @@
84
84
  "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0",
85
85
  "react-native": "^0.65.0 || ^0.66.0 || ^0.67.0 || ^0.68.0 || ^0.71.0"
86
86
  },
87
- "gitHead": "bf08d1f48c4e7939f6e4e246a2ba84189f0e68db",
87
+ "gitHead": "375efe3ae17613832fc10b212b0c3d2fce0a31cd",
88
88
  "publishConfig": {
89
89
  "access": "public"
90
90
  }
@@ -9,7 +9,7 @@ import { WithTheme, contact_is_valid, useAddGTMTag, useFileUpload, useFormFields
9
9
  import ReactGA from "react-ga4";
10
10
 
11
11
  import isEmail from "validator/lib/isEmail"
12
- import { append_current_utm_params, field_can_autoadvance, getLocalTimezone, get_time_values, get_utm_params, is_object, object_is_empty, responses_satisfy_conditions, update_local_storage } from "@tellescope/utilities"
12
+ import { append_current_utm_params, emit_gtm_event, field_can_autoadvance, getLocalTimezone, get_time_values, get_utm_params, is_object, object_is_empty, responses_satisfy_conditions, update_local_storage } from "@tellescope/utilities"
13
13
 
14
14
  export const useFlattenedTree = (root?: FormFieldNode) => {
15
15
  const flat: FormField[] = []
@@ -538,6 +538,7 @@ export const useTellescopeForm = ({ dontAutoadvance, isPublicForm, form, urlLogi
538
538
  const [repeats, setRepeats] = useState({} as Record<string, string | number>)
539
539
 
540
540
  const gaEventRef = useRef({} as Record<string, boolean>)
541
+ const gtmEventRef = useRef({} as Record<string, boolean>)
541
542
 
542
543
  let goBackURL = ''
543
544
  try {
@@ -591,6 +592,13 @@ export const useTellescopeForm = ({ dontAutoadvance, isPublicForm, form, urlLogi
591
592
  });
592
593
  }, [ga4measurementId, activeField])
593
594
 
595
+ useEffect(() => {
596
+ if (gtmEventRef.current[activeField.value.id]) return
597
+ gtmEventRef.current[activeField.value.id] = true
598
+
599
+ emit_gtm_event({ event: 'form_progress', formId: activeField.value.formId, fieldId: activeField.value.id, title: activeField.value.title })
600
+ }, [activeField])
601
+
594
602
  // placeholders for initial fields, reset when fields prop changes, since questions are now different (e.g. different form selected)
595
603
  const fieldInitRef = useRef('')
596
604
  const initializeFields = useCallback(() => (
@@ -1252,6 +1260,7 @@ export const useTellescopeForm = ({ dontAutoadvance, isPublicForm, form, urlLogi
1252
1260
  value: 2,
1253
1261
  });
1254
1262
  }
1263
+ emit_gtm_event({ event: 'form_submitted', formId: formResponse.formId })
1255
1264
  updateLocalFormResponse(formResponse.id, formResponse)
1256
1265
  options?.onPreRedirect?.() // in case redirect on success
1257
1266
  options?.onSuccess?.(formResponse)
@@ -3036,6 +3036,23 @@ export const HeightInput = ({ field, value={} as any, onChange, ...props }: Form
3036
3036
  </Grid>
3037
3037
  )
3038
3038
 
3039
+ export const include_current_url_parameters_if_templated = (url: string ) => {
3040
+ try {
3041
+ // get parameters from the current URL, and replace all values where {{URL_PARAM.paramName}} is used
3042
+ const params = new URL(window.location.href).searchParams
3043
+ return url.replace(/{{URL_PARAM\.(.*?)}}/g, (_, paramName) => {
3044
+ const value = params.get(paramName)
3045
+ console.log(paramName, value)
3046
+ if (value === null) return ''
3047
+ return value
3048
+ })
3049
+
3050
+ } catch(err) {
3051
+ console.error(err)
3052
+ }
3053
+ return url
3054
+ }
3055
+
3039
3056
  export const RedirectInput = ({ enduserId, groupId, groupInsance, rootResponseId, formResponseId, field, submit, value={} as any, onChange, responses, enduser, ...props }: FormInputProps<'Redirect'>) => {
3040
3057
  const session = useResolvedSession()
3041
3058
 
@@ -3080,13 +3097,15 @@ export const RedirectInput = ({ enduserId, groupId, groupInsance, rootResponseId
3080
3097
  if (!field.options?.redirectExternalUrl) { return }
3081
3098
 
3082
3099
  window.location.href = (
3083
- replace_enduser_template_values(
3084
- field.options.redirectExternalUrl,
3085
- {
3086
- ...session.userInfo as any,
3087
- id: eId, email, fname, lname, state, phone,
3088
- }
3089
- )
3100
+ include_current_url_parameters_if_templated(
3101
+ replace_enduser_template_values(
3102
+ field.options.redirectExternalUrl,
3103
+ {
3104
+ ...session.userInfo as any,
3105
+ id: eId, email, fname, lname, state, phone,
3106
+ }
3107
+ )
3108
+ )
3090
3109
  )
3091
3110
  })
3092
3111
  .catch(console.error)