Have your say in Community Polls: What was/is your greatest motivation to start your own business?

phone number in dataLayer pixel

phone number in dataLayer pixel

Jakub7
Visitor
1 0 0

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?

Replies 0 (0)