Setting up and tracking user interactions with embedded videos in Google Analytics involves using event tracking to capture specific actions users take while interacting with videos on your website. Here’s a step-by-step guide to help you set this up effectively:
1. Enable Enhanced Link Attribution (Optional)
Enhanced Link Attribution helps differentiate between multiple links to the same URL on a single page. This can be useful when multiple videos are embedded on the same page.
- Navigate to Admin: Click on the gear icon at the bottom left of your Google Analytics dashboard to access the Admin panel.
- View Settings: Under the View column, click on “View Settings.”
- Enhanced Link Attribution: Enable “Enhanced Link Attribution” and save changes.
2. Set Up Event Tracking for Video Interactions
Event tracking in Google Analytics allows you to monitor specific interactions with embedded videos, such as play, pause, and completion.
A. Obtain the YouTube Video ID or Vimeo Video ID
Before setting up event tracking, identify the video IDs for the embedded videos on your website:
- YouTube: Locate the video ID from the URL (e.g., for
https://www.youtube.com/watch?v=VIDEOID
, “VIDEOID” is the ID). - Vimeo: Find the video ID from the URL (e.g., for
https://vimeo.com/VIDEOID
, “VIDEOID” is the ID).
B. Implement Event Tracking Code
Add JavaScript event tracking code to each video player on your website. This code varies depending on whether you are using YouTube or Vimeo:
YouTube Video Tracking Example:
// Replace 'VIDEO_ID' with your YouTube video ID
var videoId = 'VIDEO_ID';
// Listen for the YouTube player API to be ready
function onYouTubePlayerAPIReady() {
var player = new YT.Player('player-' + videoId, {
events: {
'onStateChange': onPlayerStateChange
}
});
}
// Track YouTube video interactions
function onPlayerStateChange(event) {
var action;
switch (event.data) {
case YT.PlayerState.PLAYING:
action = 'play';
break;
case YT.PlayerState.PAUSED:
action = 'pause';
break;
case YT.PlayerState.ENDED:
action = 'ended';
break;
default:
return;
}
// Send an event to Google Analytics
ga('send', 'event', 'Videos', action, videoId);
}
Vimeo Video Tracking Example:
// Replace 'VIDEO_ID' with your Vimeo video ID
var videoId = 'VIDEO_ID';
// Listen for the Vimeo API to be ready
var player = new Vimeo.Player('player-' + videoId);
// Track Vimeo video interactions
player.on('play', function() {
ga('send', 'event', 'Videos', 'play', videoId);
});
player.on('pause', function() {
ga('send', 'event', 'Videos', 'pause', videoId);
});
player.on('ended', function() {
ga('send', 'event', 'Videos', 'ended', videoId);
});
3. Set Up Event Tracking in Google Analytics
After implementing the event tracking code, configure Google Analytics to capture these events:
- Navigate to Admin: Click on the gear icon at the bottom left of your Google Analytics dashboard to access the Admin panel.
- Goals: Under the View column, click on “Goals” and then the “+ New Goal” button.
- Goal Setup:
- Choose “Custom” as the goal type.
- Name your goal (e.g., “Video Interactions”).
- Select “Event” as the goal type.
- Configure the goal details:
- Category: Videos
- Action: play, pause, ended (based on your event tracking)
- Label: Use the video ID or other relevant information to identify the video
- Value: Optional, depending on your tracking needs
4. Verify and Save
Verify your event tracking setup to ensure Google Analytics is capturing video interactions correctly:
- Use Real-Time reports in Google Analytics to test if events are being tracked in real-time after interacting with the video on your website.
5. Analyze Video Interaction Data
Once set up, you can analyze video interaction data in Google Analytics:
- Events Overview: Navigate to “Behavior” > “Events” > “Overview” to see a summary of video interactions.
- Event Categories and Actions: Drill down into specific event categories (e.g., Videos) and actions (e.g., play, pause) to analyze user behavior.
- Secondary Dimensions: Add secondary dimensions like page URL or traffic source to gain deeper insights into where and how users interact with videos.
By following these steps, you can effectively set up and track user interactions with embedded videos in Google Analytics, gaining valuable insights into how users engage with multimedia content on your website.