Learn how to use the VTEX IO Pixel builder.
The pixel
builder allows the implementation of JavaScript scripts in HTML files. The scripts run in the head or body of every store page and can collect user data, respond to events, and connect with third-party services.
For details about creating Pixel apps, see the Pixel apps tutorial. You can find examples of available apps that use this builder in the Pixel Apps section.
Folder structure
The pixel
builder uses a folder named pixel
located in the app’s root folder.
_10pixel_10 ┣ 📄body.html_10 ┗ 📄head.html
body.html
: HTML file with the script that will run in the body of the store pages. Scripts running in the body can perform better, but some events might be missed since the execution takes place while HTML elements are rendered.head.html
: HTML file with the script that will run in the head of the store pages. Running scripts in the head can have a higher impact on performance but ensures all events are detected since the execution takes place before HTML elements are rendered.
Usage
-
Start with a template: Download the pixel-app-template.
-
Add the app settings to the manifest: Open the
manifest.json
file in the app’s root folder and add the necessary settings to work with your script in thesettingsSchema
object. For example, you can add a field to insert a Google Tag Manager ID. For more details, see Creating an interface for your app settings. -
Implement the script: Insert the script code in the
head.html
file orbody.html
file, depending on the desired implementation. The script will run on every store page. The choice between head or body execution is a trade-off of page performance against ensuring event detection and user data collection. Below is a script example._10<script>_10(function() {_10var appId = "{{settings.gtmId}}";_10_10// Add script here_10})()_10</script> -
Add scripts in specific pages or components (optional): Besides running scripts with the
pixel
builder, you can add scripts in specific pages and components using React. You can see an example in the Pixel apps tutorial. For the definition of the available events, see the pixel-app-template repository. -
Testing: Link the app to a development workspace for testing, then access the store in the development workspace to see the script in action. The URL to access the store in the development workspace uses the format
{workspace}--{accountName}.myvtex.com
, where{workspace}
is your workspace and{accountName}
is your account name. You may need to perform the programmed actions to trigger the events set in your script, such as adding a product to the shopping cart.