AdWords
3.2K members online now
3.2K members online now
Dive into advanced features like Remarketing, Flexible Bid Strategies, AdWords Editor, and AdWords Scripts
Guide Me
star_border
Reply

Adwords Script: YouTube Placement Finder

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hello everyone. I want to share with you script which find youtube videos by query in search.

 

I use it to find most relevant youtube placements for my GDN and Video campaigns.

 

Instruction: 

 

1. Google spreadsheet example - https://docs.google.com/spreadsheets/d/1dx5tBvcuvBffv0ipDyVgX6pTdW1paVnSecxigalCl5E/ -

You can make a copy or create new spreadsheet with sheets: "Keywords" and "Results"

 

2. Authorize script and Enable Youtube in Advanced APIs.

3. Add queries to the sheet 'Keywords'

4. After first run in logs you'll find error.

 

 Access Not Configured. YouTube Data API has not been used in project XXXXXXXXXXXX before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/youtube/overview?project=XXXXXXXXXXXX then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.

 

5. Start a preview and you'll find all video IDs and title in the 'Results' sheet.

 

This script works very fast and you can find thousands videos in minutes.

 

/******************************************
* YouTube Placement Finder 
*
* Version 2.0 
*
* - Improved speed
* - Added 'Results' cleaner
*
* Created by: Dmytro Tonkikh
* dmitry.tonkikh@gmail.com ******************************************/ function main() { var spreadsheetUrl = "https://docs.google.com/spreadsheets/d/1dx5tBvcuvBffv0ipDyVgX6pTdW1paVnSecxigalCl5E/edit#gid=0"; var ss = SpreadsheetApp.openByUrl(spreadsheetUrl); var kwSheet = ss.getSheetByName('Keywords'); var resSheet = ss.getSheetByName('Results'); var lastRow = kwSheet.getLastRow(); resSheet.clear(); var range = kwSheet.getRange(1, 1, lastRow, 1); var values = range.getValues(); Logger.log(values.length); var placements = []; for(var i = 0; values.length > i; i++) { var query = values[i][0]; var results = YouTube.Search.list('id,snippet', {q: query, maxResults: 25}); for (var j in results.items) { var item = results.items[j]; placements.push([item.id.videoId,item.snippet.title]); } } resSheet.getRange(1, 1, placements.length, placements[0].length).setValues(placements); }

 

PS: Let me know if you find this script useful. 

 

1 Expert replyverified_user

Re: Adwords Script: YouTube Placement Finder

Community Manager
# 2
Community Manager
Thanks for sharing, Dmytro!

Adwords Script: YouTube Placement Finder

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

Great...Can i make a column with keywords i would like to exclude?

Adwords Script: YouTube Placement Finder

Visitor ✭ ✭ ✭
# 4
Visitor ✭ ✭ ✭

@ThorstenO Yes, you can fetch all videos and then exculed them. I have another script which looking for childrens channels  - https://www.semrush.com/blog/how-to-exclude-childrens-channels-from-youtube-advertising/, you can setup this script to exclude channels.

Adwords Script: YouTube Placement Finder

Visitor ✭ ✭ ✭
# 5
Visitor ✭ ✭ ✭

I got this script working and it's fantastic. Any idea what I can do with the undefined ID values? It looks like these are playlists and youtube channel names without the URL.

Adwords Script: YouTube Placement Finder

Visitor ✭ ✭ ✭
# 6
Visitor ✭ ✭ ✭

Thanx @Cesar m. Unfortunatly undefined came when YouTube API answer is null( 

Adwords Script: YouTube Placement Finder

[ Edited ]
Visitor ✭ ✭ ✭
# 7
Visitor ✭ ✭ ✭

Script working great with YouTube Video Campains and also GDN. Sometimes I have errors in Logs:

 

1) TypeError: Cannot read property "snippet" from undefined.
2) TypeError: Cannot read property "length" from undefined.
3) The coordinates or dimensions of the range are invalid. (line 96)
I'm use your script from - https://tonkikh.github.io/channels-cleaner/