phone number in dataLayer pixel

Topic summary

A developer is working with Shopify’s Web Pixels API to capture form submission data using the form_submitted event. They have successfully implemented code that extracts email input values using regex pattern matching.

Current Challenge:
The form contains three inputs (email, phone, message), but the developer only knows how to capture the email field. They need guidance on how to reference and extract values from the phone and message inputs.

Technical Context:

  • Using analytics.subscribe('form_submitted') event listener
  • Currently filtering form elements by matching email-related IDs/names with regex
  • Planning to send captured data to third-party servers via fetch POST request

Status: The question remains unanswered, with the developer seeking suggestions on the proper approach to access these additional form fields.

Summarized with AI on November 3. AI used: claude-sonnet-4-5-20250929.

Hello

I have this code here

https://shopify.dev/docs/api/web-pixels-api/dom-events/form_submitted

And it works

analytics.subscribe(‘form_submitted’, (event) => {
// Example for accessing event data
const element = event.data.element;

const elementId = element.id;
const formAction = element.action;
const emailRegex = /email/i;
const [email] = element.elements
.filter((item) => emailRegex.test(item.id) || emailRegex.test(item.name))
.map((item) => item.value);
const formDetails = element.elements.map((item) => {
return {
id: item.id,
name: item.name,
value: item.value,
};
});

const payload = {
event_name: event.name,
event_data: {
id: elementId,
url: formAction,
email: email,
formDetails: formDetails,
},
};

// Example for sending event to third party servers
fetch(‘https://example.com/pixel’, {
method: ‘POST’,
body: JSON.stringify(payload),
keepalive: true,
});
});

Problem is, my form have also “phone” input and “message” input.
I would like to refer to these inputs and i don’t know how. “email” input is working, but i don’t understand how.

Any suggestions?