Groups
Groups

Script doesn't find Shopping campaign??

24 views
Skip to first unread message

Jonas Kold

unread,
Nov 30, 2025, 11:49:47 PM (5 days ago) Nov 30
to Google Ads Scripts Forum
The ads script log keeps reporting error on campaign name, when i preview it..

29.11.2025 11.35.19

FEJL: Kampagnen med ID 23296359240 blev ikke fundet.
However, then campaign IS active and running, and i've tried both ID and name, however it still doesn't find it. Whats going wrong?

Here is the script:

/**
 * CONFIG: udfyld enten CAMPAIGN_NAMES eller CAMPAIGN_IDS (eller begge)
 */
var CONFIG = {
  BRAND_TERMS: ['luxvuf','lux vuf','vuflux','luksushund','luxhund','luxus hund','luksus hund','lux hund','luxvuf dk','luxushund','luxdog'],
  CAMPAIGN_NAMES: ['Luxvuf - Brand - Shopping'], // valgfrit
  CAMPAIGN_IDS: [], // valgfrit - f.eks. [12345678, 98765432]
  DAYS: 30
};

function main() {
  var campaignIds = [];

  // 1) Hvis der er navne: find dem (robust søgning: STARTS_WITH eller IN)
  if (CONFIG.CAMPAIGN_NAMES && CONFIG.CAMPAIGN_NAMES.length) {
    var nameSelector = AdsApp.campaigns()
        .withCondition("AdvertisingChannelType = SHOPPING")
        .withCondition("Name STARTS_WITH 'Luxvuf - Brand'"); // hvis du ønsker præcis IN, skift linjen
    var it = nameSelector.get();
    while (it.hasNext()) {
      campaignIds.push(it.next().getId());
    }
  }

  // 2) Hvis der er eksplicitte IDs: valider dem først
  if (CONFIG.CAMPAIGN_IDS && CONFIG.CAMPAIGN_IDS.length) {
    CONFIG.CAMPAIGN_IDS.forEach(function(id){
      var sel = AdsApp.campaigns().withIds([id]).get();
      if (sel.hasNext()) {
        campaignIds.push(id);
      } else {
        Logger.log("ADVARSEL: Kampagne-ID " + id + " ikke fundet i denne konto.");
      }
    });
  }

  // Fjern duplikater
  campaignIds = campaignIds.filter(function(v,i,a){ return a.indexOf(v) === i; });

  if (campaignIds.length === 0) {
    Logger.log("FEJL: Ingen kampagner fundet i denne konto ud fra CONFIG. Tjek om du kører i MCC eller at navne/IDs er korrekte.");
    // Hjælpe-log: list tilgængelige shopping-kampagner i denne konto
    var debugIt = AdsApp.campaigns().withCondition("AdvertisingChannelType = SHOPPING").get();
    Logger.log("Tilgængelige SHOPPING-kampagner i denne konto:");
    while (debugIt.hasNext()) {
      var c = debugIt.next();
      Logger.log(" - " + c.getId() + " : " + c.getName());
    }
    return;
  }

  Logger.log("Fortsætter med kampagner: " + campaignIds.join(", "));

  // 3) Hent rapport (bemærk: 'CampaignType' som string)
  var query = ""
    + "SELECT Query, CampaignId, Clicks "
    + "FROM SEARCH_QUERY_PERFORMANCE_REPORT "
    + "WHERE Clicks > 0 "
    + "AND CampaignId IN [" + campaignIds.join(",") + "] "
    + "AND CampaignType = 'SHOPPING' "
    + "DURING LAST_" + CONFIG.DAYS + "_DAYS";

  var report = AdsApp.report(query);
  var rows = report.rows();

  while (rows.hasNext()) {
    var row = rows.next();
    var q = row['Query'].toLowerCase();
    var cid = parseInt(row['CampaignId'], 10);

    var isBrand = CONFIG.BRAND_TERMS.some(function(term){ return q.indexOf(term) !== -1; });

    if (!isBrand) {
      Logger.log("Tilføjer negativ (exact): [" + q + "] for kampagne " + cid);

      // Sikker hentning af kampagnen før operation
      var campSel = AdsApp.campaigns().withIds([cid]).get();
      if (campSel.hasNext()) {
        var camp = campSel.next();
        try {
          camp.createNegativeKeyword("[" + q + "]");
        } catch (e) {
          Logger.log("FEJL ved oprettelse af negativ for '" + q + "': " + e);
        }
      } else {
        Logger.log("ADVARSEL: Kampagne " + cid + " ikke fundet ved oprettelsestidspunkt.");
      }
    }
  }

  Logger.log("Færdig.");
}
Luk
Kør
Gem
Forhåndsvisning

Google Ads Scripts Forum Advisor

unread,
Dec 1, 2025, 2:31:08 AM (5 days ago) Dec 1
to adwords...@googlegroups.com

Hi,

Thank you for reaching out to the Google Ads Scripts support team.

Please be noted that the method “AdsApp.campaigns()” you are using will only iterate through Search and Display campaigns. To select Shopping campaigns, you can use the “AdsApp.shoppingCampaigns()” method. Additionally, I would suggest that you refer to the “AdsApp.​ShoppingCampaignSelector” and “Shopping” documents for sample code.

I hope this helps! If you are still facing any issues, feel free to get back to us with the following details.

  • Google Ads account ID/CID
  • Name of the affected script
  • Screenshot of the issue (if any)
You can share the requested details via Reply privately to the author option or a direct private reply to this email.

Thanks,
 
Google Logo Google Ads Scripts Team

Feedback
How was our support today?

rating1    rating2    rating3    rating4    rating5
[2025-12-01 07:30:43Z GMT] This message is in relation to case "ref:!00D1U01174p.!500Ht01vUa8F:ref" (ADR-00346261)



Rakib Sandwip

unread,
Dec 2, 2025, 8:07:17 AM (4 days ago) Dec 2
to Jonas Kold via Google Ads Scripts Forum

--
-- You received this message because you are subscribed to the Google Groups AdWords Scripts Forum group. Please do not reply to this email. To post to this group or unsubscribe please visit https://developers.google.com/adwords/scripts/community.
---
You received this message because you are subscribed to the Google Groups "Google Ads Scripts Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adwords-scrip...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/adwords-scripts/cab8b27e-6197-4e6b-b892-866e41ba35f9n%40googlegroups.com.

Ishu Ishu

unread,
Dec 2, 2025, 8:07:43 AM (4 days ago) Dec 2
to (Deprecated) Google Ads Scripts Forum

You received this message because you are subscribed to the Google Groups "(Deprecated) Google Ads Scripts Forum" group.

To unsubscribe from this group and stop receiving emails from it, send an email to adwords-scrip...@googlegroups.com.

rabbi hosen

unread,
Dec 2, 2025, 8:08:06 AM (4 days ago) Dec 2
to (Deprecated) Google Ads Scripts Forum

You received this message because you are subscribed to the Google Groups "(Deprecated) Google Ads Scripts Forum" group.

To unsubscribe from this group and stop receiving emails from it, send an email to adwords-scrip...@googlegroups.com.

Said Haman

unread,
Dec 2, 2025, 8:08:51 AM (4 days ago) Dec 2
to (Deprecated) Google Ads Scripts Forum

Vào Thứ 3, 2 thg 12, 2025 vào lúc 20:07 (Deprecated) Google Ads Scripts Forum <adwords...@googlegroups.com> đã viết:

Tafsia Tahrim Marufa Marufa

unread,
Dec 2, 2025, 8:12:26 AM (4 days ago) Dec 2
to Jonas Kold via Google Ads Scripts Forum

Vào Thứ 2, 1 thg 12, 2025 vào lúc 11:49 Jonas Kold via Google Ads Scripts Forum <adwords...@googlegroups.com> đã viết:

Trung Nguyễn

unread,
Dec 2, 2025, 8:17:08 AM (4 days ago) Dec 2
to (Deprecated) Google Ads Scripts Forum

Vào Thứ 3, 2 thg 12, 2025 vào lúc 20:07 (Deprecated) Google Ads Scripts Forum <adwords...@googlegroups.com> đã viết:

duy minh

unread,
Dec 2, 2025, 8:17:59 AM (4 days ago) Dec 2
to Google Ads Scripts Forum on behalf of adsscripts

Vào Thứ 2, 1 thg 12, 2025 vào lúc 14:30 Google Ads Scripts Forum on behalf of adsscripts <adwords...@googlegroups.com> đã viết:
--
-- You received this message because you are subscribed to the Google Groups AdWords Scripts Forum group. Please do not reply to this email. To post to this group or unsubscribe please visit https://developers.google.com/adwords/scripts/community.
---
You received this message because you are subscribed to the Google Groups "Google Ads Scripts Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adwords-scrip...@googlegroups.com.

Trung Nguyễn

unread,
Dec 2, 2025, 8:18:53 AM (4 days ago) Dec 2
to (Deprecated) Google Ads Scripts Forum

Vào Thứ 3, 2 thg 12, 2025 vào lúc 20:16 Trung Nguyễn <carnatio...@gmail.com> đã viết:

Rani Uikey

unread,
Dec 2, 2025, 8:19:03 AM (4 days ago) Dec 2
to (Deprecated) Google Ads Scripts Forum

You received this message because you are subscribed to the Google Groups "(Deprecated) Google Ads Scripts Forum" group.

To unsubscribe from this group and stop receiving emails from it, send an email to adwords-scrip...@googlegroups.com.

Anh Đức

unread,
Dec 3, 2025, 4:28:11 AM (3 days ago) Dec 3
to (Deprecated) Google Ads Scripts Forum
thank you so much

Vào Thứ 3, 2 thg 12, 2025 vào lúc 20:07 (Deprecated) Google Ads Scripts Forum <adwords...@googlegroups.com> đã viết:
You received this message because you are subscribed to the Google Groups "(Deprecated) Google Ads Scripts Forum" group.

To unsubscribe from this group and stop receiving emails from it, send an email to adwords-scrip...@googlegroups.com.

Rose Lisa

unread,
Dec 3, 2025, 4:29:45 AM (3 days ago) Dec 3
to (Deprecated) Google Ads Scripts Forum
thank you so much

Vào Thứ 4, 3 thg 12, 2025 vào lúc 16:27 (Deprecated) Google Ads Scripts Forum <adwords...@googlegroups.com> đã viết:

Anh Mai

unread,
Dec 3, 2025, 4:31:03 AM (3 days ago) Dec 3
to (Deprecated) Google Ads Scripts Forum
thank you so much

Vào Thứ 4, 3 thg 12, 2025 vào lúc 16:29 (Deprecated) Google Ads Scripts Forum <adwords...@googlegroups.com> đã viết:

Nobara Kugisaki

unread,
Dec 3, 2025, 4:39:25 AM (3 days ago) Dec 3
to (Deprecated) Google Ads Scripts Forum
thank you so much

Vào Thứ 4, 3 thg 12, 2025 vào lúc 16:29 (Deprecated) Google Ads Scripts Forum <adwords...@googlegroups.com> đã viết:

Shoto Todoroki

unread,
Dec 3, 2025, 4:40:39 AM (3 days ago) Dec 3
to (Deprecated) Google Ads Scripts Forum
thank you so much

Vào Thứ 4, 3 thg 12, 2025 vào lúc 16:29 (Deprecated) Google Ads Scripts Forum <adwords...@googlegroups.com> đã viết:

Itadori Yuuji

unread,
Dec 3, 2025, 4:42:07 AM (3 days ago) Dec 3
to (Deprecated) Google Ads Scripts Forum
thank you so much

Vào Thứ 4, 3 thg 12, 2025 vào lúc 16:29 (Deprecated) Google Ads Scripts Forum <adwords...@googlegroups.com> đã viết:

Manjirou Sano

unread,
Dec 3, 2025, 4:45:19 AM (3 days ago) Dec 3
to Google Ads Scripts Forum on behalf of adsscripts
thank you so much

Vào Thứ 2, 1 thg 12, 2025 vào lúc 14:30 Google Ads Scripts Forum on behalf of adsscripts <adwords...@googlegroups.com> đã viết:

Hi,

--
-- You received this message because you are subscribed to the Google Groups AdWords Scripts Forum group. Please do not reply to this email. To post to this group or unsubscribe please visit https://developers.google.com/adwords/scripts/community.
---
You received this message because you are subscribed to the Google Groups "Google Ads Scripts Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adwords-scrip...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages
Search
Clear search
Close search
Google apps
Main menu