The `form_submitted` event logs an instance where a form on a page is submitted.
import {register} from '@shopify/web-pixels-extension';
register(({analytics}) => {
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,
});
});
});
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,
});
});
The `form_submitted` event logs an instance where a form element on the page has been submitted
The client-side ID of the customer, provided by Shopify
The ID of the customer event
The name of the customer event
The timestamp of when the customer event occurred, in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format
An object that contains data about a form element type
The action attribute of a form element
The id attribute of an element
An object that contains data about an input element type
The id attribute of an element
The name attribute of an element
A string representation of the tag of an element
The type attribute of an element. Often relevant for an input or button element.
The value attribute of an element. Often relevant for an input element.