Yahoo! JAPAN Ads Script | Developer Center
日本語Automatic upload of audience lists (customer data)
Updates
September 2, 2025: Removed "When uploading from Google Drive."
January 8, 2025: Added notice that column headings are required on the first line of the spreadsheet.
July 24, 2024: Added support for V202406 scripts. Changed page layout.
Table of contents
Script overview
Display ads allow you to upload files of customer data held by advertisers and import them into your audience list.
Yahoo! JAPAN Ads Script can automate this import process. By using automatic uploads, you can always take advantage of the latest data.
Create import files
Learn how to Import data and create audience list for customer data
Before you begin
1. Connect your Google account with Yahoo! JAPAN Ads Script.
Learn how to Connect with Google account
*If you have already connected, start from the next step.
2. Prepare a spreadsheet.
(1) In column A of the Google Sheets, enter the customer data as shown below (example below is aaid)
Be sure to include the following column headings on the first line to match the data you are entering (headings do not require hashing):
Data type | Header contents |
---|---|
Email address | |
Phone number | Phone |
Identifiers for app ads (IDFA or AAID) | Mobile Device ID |
(2) Obtain the spreadsheet ID from (1)
Learn moreHow to find the spreadsheet ID
3. In the create script screen of the dashboard, set the following sample code described in this page.
*Learn more about Create and run Yahoo! JAPAN Ads Script.
4. After you complete the script settings on the dashboard, set the script frequency.
*Learn more about Set up Yahoo! JAPAN Ads Script frequency.
Explanation of each constant in the sample code
This section describes how to set each constant in the following sample codes.
■Audience list ID
Check and specify the Audience list ID in the dashboard.
const AUDIENCE_LISTID = 1234567890;
*For more information about how to check audience list ID
■Spreadsheet settings (only when uploading from Google Spreadsheets)
Specify the spreadsheet ID and sheet name obtained in step 2 of "Before you begin."
Constant to set | How to set up |
---|---|
const SPREAD_SHEET_ID = 'SPREAD_SHEET_ID'; | Spreadsheet ID between ' (single quotes) |
const SHEET_NAME = 'SHEET_NAME'; | Sheet name between ' (single quotes) |
■Upload type
The default value is MAIL_ADDRESS_AND_PHONE_NUMBER (hashed email address or phone number).
const UPLOAD_TYPE = 'MAIL_ADDRESS_AND_PHONE_NUMBER';
Change MAIL_ADDRESS_AND_PHONE_NUMBER to the following settings as needed.
Value to set | Description |
---|---|
IDFA | Ad identifier for iOS devices. |
AAID | Ad identifier for Android devices. |
MAIL_ADDRESS_AND_PHONE_NUMBER | Hashed email addresses or phone numbers. *Unlike uploading in the dashboard, hashing is required from Yahoo! JAPAN Ads Script. Learn more about Import data and create audience list for customer data |
■ Email or Slack notification of results
If you want to notify the results by email or Slack, refer to this page for details.
Sample codes
Copy the following scripts, including comments in gray, and paste them into the script input, then set up the constants according to the instructions in the script.
Set the necessary constants according to the usage described in "Explanation of each constant in the sample code" or in the script.
/*
■Script
Uploads the audience list (customer data) from the specified Google Spreadsheet.
■How to use
1. Use this script as your Display Ads script.
2. Set the constants as follows.
■Constant
・AUDIENCE_LISTID: Check and specify the audience list ID on the dashboard
・SPREAD_SHEET_ID Buttigieg // Specify the splet sheet ID
・SHEET_NAME //Sheet name of spreadsheet
・UPLOAD_TYPE: IDFA, AAID, MAIL_ADDRESS_AND_PHONE_NUMBER can be used.
Details→https://ads-developers.yahoo.co.jp/ja/ads-script/product-guide/reference/enums/display.AudienceListServiceUploadUserListUploadType.html
・FLAG_MAIL: true if the result should be emailed, false otherwise
・MAIL_TO: Yahoo! BusinessID to which the email is sent
・MAIL_TITLE: Email title
・FLAG_SLACK: true to send the result to Slack, false otherwise
・URL_FETCH_APP:Slack"s Webhook URL
*/
//Constants that need to be set
const AUDIENCE_LISTID = 1234567890;
const SPREAD_SHEET_ID = 'SPREAD_SHEET_ID';
const SHEET_NAME = 'SHEET_NAME'
const UPLOAD_TYPE = 'MAIL_ADDRESS_AND_PHONE_NUMBER';
const FLAG_MAIL = false;
const MAIL_TO = ['Yahoo! JAPAN Business ID'];
let MAIL_TITLE = 'Automatic Audience List Upload';
const FLAG_SLACK = false;
const URL_FETCH_APP = 'SLACK_WEBHOOK_URL';
//Constants that do not need to be set (changing them will cause an error)
const accountId = AdsUtilities.getCurrentAccountId();
let TEXT_MESSAGE_ARRAY = [];
function main() {
try {
const ss = validateAndGetSpreadsheet();
const sh = validateAndGetSheet(ss);
let ssDataArray = sh.getDataRange().getValues();
let fileContent = '';
ssDataArray.forEach(row => {
fileContent += row[0] + '\n';
});
//Spreadsheet is uncompressed · v14 or later can be used as is UP
let uploadList = Display.AudienceListService.uploadUserList(accountId, AUDIENCE_LISTID, UPLOAD_TYPE, 'NONE', fileContent).rval;
if (uploadList.values[0].operationSucceeded) {
sendMailAndSlack ('Automatic upload of audience list complete. ');
} else {
throw new Error('An error occurred during upload');
}
} catch (error) {
MAIL_TITLE = '!!エラー!!' + MAIL_TITLE;
sendMailAndSlack ('Automatic upload of audience list error! !Check the log on the dashboard for details. \n' + error);
throw error;//Rethrow to cause an error on the dashboard
}
}
function validateAndGetSpreadsheet() {
if (SPREAD_SHEET_ID === 'SPREAD_SHEET_ID' || SPREAD_SHEET_ID === '') {
throw new Error ('Set the spreadsheet ID. ');
}
try {
return SpreadsheetApp.openById(SPREAD_SHEET_ID);
} catch (e) {
throw new Error('Could not open spreadsheet. Check that the spreadsheet ID or permissions on the spreadsheet are correct. ' + e);
}
}
function validateAndGetSheet(ss) {
if (SHEET_NAME === '') {
throw new Error ('Set the sheet name. ');
}
const sh = ss.getSheetByName(SHEET_NAME);
if (sh === null) {
throw new Error('Could not open sheet. Check the sheet name. ');
}
return sh;
}
function sendMailAndSlack(text){
logAndMessage(text);
validateAndSendMail();
validateAndSendSlack();
}
function logAndMessage(text) {
Logger.log(text);
TEXT_MESSAGE_ARRAY.push(text);
}
function validateAndSendMail() {
if (FLAG_MAIL) {
if (MAIL_TO.length < 1 || !MAIL_TO.every(str => typeof str === 'string' && /^[a-zA-Z0-9]+$/.test(str))) {
throw new Error('Set your Yahoo! JAPAN Business ID. Processes performed before sending the email have been completed. ');
}
MailApp.sendEmail({
to: MAIL_TO,
Subject: MAIL_TITLE,
<body> TEXT_MESSAGE_ARRAY.join('\n')
});
}
}
function validateAndSendSlack() {
if (FLAG_SLACK) {
if (URL_FETCH_APP === 'SLACK_WEBHOOK_URL' || URL_FETCH_APP === '') {
throw new Error ('Set the Slack Webhook URL. Processes performed before sending Slack have been completed. ');
}
UrlFetchApp.fetch(URL_FETCH_APP, {
method: 'post',
contentType: 'application/json',
payload: JSON.stringify({
text: TEXT_MESSAGE_ARRAY.join('\n'),
.}),
});
}
}
Check results
When you checked your audience list from the Campaign Management Tool, if the User Size reflects the number of uploads, you are done.
Tips
After creating your audience list, it may take up to 48 hours to check user size.
Example of the Campaign Management Tool