Tracking clicks on elements on your website page using VWO is a simple process where you define the element to track and then add the VWO SmartCode snippet to the source code of the webpage.
However, tracking clicks for YouTube videos is different because the videos are present inside the iFrame hosted on the YouTube domain, where it is not possible to place the VWO code.
To track clicks on your YouTube videos using VWO, follow these steps:
- Add Custom Conversion goal to track clicks.
- Add the code snippet under the Pre-JS section inside the VWO editor.
Add Custom Conversion Goal to Track Clicks
- In the section for defining goals, add Custom Conversion as the goal you want to track.
- In the URL field, type the URL of the page where the YouTube video is present and then click Next.
On the last page of the campaign creation process, copy the corresponding code snippet generated for the Custom Conversion goal you have added to the campaign. You will need this code snippet in the next step.
Add the code snippet under the Pre-JS section inside the VWO editor
To complete the videos, click tracking configuration, add the following code snippet in the Pre-JS section of the VWO code editor. Adding the Pre-JS code snippet ensures that the code is executed first before the variation changes are displayed.
Replace the goal code snippet with your own goal code snippet in the above code snippet.
You can get the embed video URL from the embed code, as shown below:
Tracking YouTube Video Clicks for a Split URL Test
Tracking YouTube video clicks in a Split URL test is slightly different and involves making changes to the source code of the website where the video is posted, or You can also use Google Tag Manager (GTM) for the same.
After creating the custom conversion goal and adding the page URL where the video is, add the following code snippet on the webpage where the YouTube video is available or add the same code snippet via GTM. Make sure to replace the goal code snippet with your own goal code snippet in the code snippet.