You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 18, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Apr 18, 2026. It is now read-only.
I want to create bulk impression tracker via the CM360 APi! #1214
Issues in Your Current Code:
Recursive call inside the same function:
You're calling _createOneTrackingCreative(ss, values[i]) inside itself, but this function is already meant to create one creative. That loop logic belongs elsewhere.
Use of values is unclear:
values is undefined in this function — it's likely meant to be a list of creative data rows. But that should be passed from outside this function, or handled in a wrapper function.
Incorrect naming of the resource object:
You created creativeResource but then are trying to use TrackingcreativeResource in the insert call, which will throw an error.
return is inside the loop:
This causes the loop to stop after the first iteration.
Recommended Refactored Code:
Here’s a clear separation of logic:
One function to create a single creative (_createOneTrackingCreative)
Another function to loop over rows and call the above one (_bulkCreateTrackingCreatives)
i will write the code for you;
function _createOneTrackingCreative(singleTrackingCreativeArray) {
var profileID = _fetchProfileId();
var advertiserId = singleTrackingCreativeArray[0];
var campaignId = singleTrackingCreativeArray[1];
var name = singleTrackingCreativeArray[2];
var width = parseInt(singleTrackingCreativeArray[3]);
var height = parseInt(singleTrackingCreativeArray[4]);
var creativeType = singleTrackingCreativeArray[5];
var newCreative = DoubleClickCampaigns.Creatives.insert(creativeResource, profileID);
return newCreative;
}
function _bulkCreateTrackingCreatives() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Creatives");
var values = sheet.getDataRange().getValues();
var profileID = _fetchProfileId(); // if needed again
for (var i = 1; i < values.length; i++) { // skip header
var singleRow = values[i];
try {
var newCreative = _createOneTrackingCreative(singleRow);
var rowNum = i + 1;
sheet.getRange('H' + rowNum).setValue(newCreative.id).setBackground('lightgray');
} catch (e) {
Logger.log("Error on row " + rowNum + ": " + e.toString());
sheet.getRange('H' + rowNum).setValue("ERROR").setBackground('red');
}
Activity
samarthupx commentedon Jul 2, 2025
Issues in Your Current Code:
Recursive call inside the same function:
You're calling _createOneTrackingCreative(ss, values[i]) inside itself, but this function is already meant to create one creative. That loop logic belongs elsewhere.
Use of values is unclear:
values is undefined in this function — it's likely meant to be a list of creative data rows. But that should be passed from outside this function, or handled in a wrapper function.
Incorrect naming of the resource object:
You created creativeResource but then are trying to use TrackingcreativeResource in the insert call, which will throw an error.
return is inside the loop:
This causes the loop to stop after the first iteration.
Here’s a clear separation of logic:
One function to create a single creative (_createOneTrackingCreative)
Another function to loop over rows and call the above one (_bulkCreateTrackingCreatives)
i will write the code for you;
function _createOneTrackingCreative(singleTrackingCreativeArray) {
var profileID = _fetchProfileId();
var advertiserId = singleTrackingCreativeArray[0];
var campaignId = singleTrackingCreativeArray[1];
var name = singleTrackingCreativeArray[2];
var width = parseInt(singleTrackingCreativeArray[3]);
var height = parseInt(singleTrackingCreativeArray[4]);
var creativeType = singleTrackingCreativeArray[5];
var creativeResource = {
"name": name,
"advertiserId": advertiserId,
"campaignId": campaignId,
"size": {
"width": width,
"height": height
},
"active": true,
"type": creativeType
};
var newCreative = DoubleClickCampaigns.Creatives.insert(creativeResource, profileID);
return newCreative;
}
function _bulkCreateTrackingCreatives() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Creatives");
var values = sheet.getDataRange().getValues();
var profileID = _fetchProfileId(); // if needed again
for (var i = 1; i < values.length; i++) { // skip header
var singleRow = values[i];
}
}
Davin909 commentedon Jul 10, 2025
#1214 (comment)