This guide will walk you through the process of finding the querySelector for an email input field on your website. This querySelector is essential for our pixel to accurately identify the email input fields across multiple pages of your website.
To ensure our pixel can track user interactions with email input fields on your website, we need to identify the correct querySelector for each input field. This process involves using browser developer tools to locate the specific selector that corresponds to the email input field.
Before you begin, ensure you have the following:
Ctrl+Shift+I
(Windows/Linux) or Cmd+Option+I
(Mac) to open the Developer Tools.
If the email input field has a unique id
attribute, you can use it directly as the querySelector.
document.querySelector('#emailInputID')
If the email input field has a class attribute, you can use the class as the querySelector. Note that if multiple elements share the same class, you might need to make the selector more specific.
document.querySelector('.emailInputClass')
If the email input field has specific attributes, you can use attribute selectors. This is useful for fields identified by type
, name
, or other attributes.
document.querySelector('input[type="email"]') document.querySelector('input[name="email"]')
If the email input field is within a specific section or nested within other elements, you can use hierarchical selectors to pinpoint it.
document.querySelector('form#signupForm input[type="email"]') document.querySelector('div.registration-container input.emailInputClass')
Once the email input field is highlighted, right-click on the HTML element and select Copy > Copy selector. This will copy the CSS selector for the email input field to your clipboard.
This approach is not recommended because it is prone to break with any change that’s made to your websites html, but if you are not able to do any of the ones above feel free to use this one, just keep in mind you might have to update your querySelectors a lot more
document.querySelectorAll('PASTE_SELECTOR_HERE')
and press Enter
. Replace PASTE_SELECTOR_HERE
with the selector you copied or constructed.NodeList [...]
will appear like in the image below. If NodeList(x)
appears where x is a number bigger than 1 than it means multiple nodes where found for the same selector, if this happens then you have to be more specific with the querySelector. In the image below you see what you should expect (disregard the body and the array content)
input[type="email"]#uniqueID
).