@@ -35,12 +35,14 @@ function readFieldsetLabel(form, classFragment) {
3535}
3636
3737/** modal vs inline, from the form's placement. */
38- function getFormType ( form ) {
38+ export function getFormType ( form ) {
3939 return form . closest ( '.modal' ) ? 'modal' : 'inline' ;
4040}
4141
42- /** header / footer / body, from the form's placement. */
43- function getFormSource ( form ) {
42+ /** header / footer / body, from the carried opener origin or the form's placement. */
43+ export function getFormSource ( form ) {
44+ const carried = form . closest ( '[data-form-source]' ) ?. dataset . formSource ;
45+ if ( carried === 'header' || carried === 'footer' || carried === 'body' ) return carried ;
4446 if ( form . closest ( 'header, .header' ) ) return 'header' ;
4547 if ( form . closest ( 'footer, .footer' ) ) return 'footer' ;
4648 return 'body' ;
@@ -60,6 +62,23 @@ function collectLeadDataPoints(form) {
6062 } ;
6163}
6264
65+ /**
66+ * The BR.430 field set shared by `formStart` and `formSubmit` — same shape, read fresh at
67+ * whatever point the caller fires. PII fields are Y/N presence flags only.
68+ * @param {HTMLFormElement } form
69+ * @returns {{formType:string, formSource:string, leadId:null, eCommEntryPoint:'N', pageUrl:string} }
70+ */
71+ export function buildLeadFormFields ( form ) {
72+ return {
73+ formType : getFormType ( form ) ,
74+ formSource : getFormSource ( form ) ,
75+ leadId : null ,
76+ eCommEntryPoint : 'N' ,
77+ pageUrl : window . location . href ,
78+ ...collectLeadDataPoints ( form ) ,
79+ } ;
80+ }
81+
6382/**
6483 * Fire the `formSubmit` analytics event with the lead-form data points. PII is emitted as Y/N
6584 * presence flags only. `leadId` is passed through (currently null until the backend returns it).
@@ -100,12 +119,9 @@ function sendDataToAnalytics(form, options = {}) {
100119 formElement : form ,
101120 quoteType,
102121 serviceType,
103- formType : getFormType ( form ) ,
104- formSource : getFormSource ( form ) ,
122+ ...buildLeadFormFields ( form ) ,
105123 leadId,
106124 eCommEntryPoint,
107- pageUrl : window . location . href ,
108- ...collectLeadDataPoints ( form ) ,
109125 } ) ;
110126}
111127
0 commit comments