This is the legacy documentation for Google Ads scripts. Go to the current docs.

Mobile Apps

Stay organized with collections Save and categorize content based on your preferences.

Add a mobile app extension to a campaign

function addMobileApp() {
  var campaignIterator = AdsApp.campaigns()
      .withCondition('Name = "INSERT_CAMPAIGN_NAME_HERE"')
      .get();
  if (campaignIterator.hasNext()) {
    var campaign = campaignIterator.next();
    // See https://support.google.com/google-ads/answer/2402582 for details on how
    // to obtain applications specific store id
    var newMobileApp = AdsApp.extensions().newMobileAppBuilder()
        .withAppId('store specific app id')                  // required
        .withStore('Android')                                // required
        .withLinkText('Download Android App Here')           // required
        .withFinalUrl('http://wwww.example.com/androidApp')  // required
        .withStartDate({day: 12, month: 9, year: 2013})      // optional
        .build()
        .getResult();

    // Add mobile app to campaign. Adding mobile apps to ad groups is similar.
    campaign.addMobileApp(newMobileApp);
  }
}

Get mobile app extensions for a campaign

function getMobileAppsForCampaign() {
  var campaignIterator = AdsApp.campaigns()
      .withCondition('Name = "INSERT_CAMPAIGN_NAME_HERE"')
      .get();
  if (campaignIterator.hasNext()) {
    var campaign = campaignIterator.next();
    var mobileAppsIterator = campaign.extensions().mobileApps().get();

    while (mobileAppsIterator.hasNext()) {
      var mobileApp = mobileAppsIterator.next();
      Logger.log('Mobile app id: ' + mobileApp.getAppId() +
          ', link text: ' + mobileApp.getLinkText() +
          ', final URL: ' + mobileApp.urls().getFinalUrl());
    }

    Logger.log(mobileAppsIterator.totalNumEntities() +
        ' mobile apps in the account');
  }
}

Get stats for mobile app extensions in a campaign

function getMobileAppStats() {
  var campaignIterator = AdsApp.campaigns()
      .withCondition('Name = "INSERT_CAMPAIGN_NAME_HERE"')
      .get();
  if (campaignIterator.hasNext()) {
    var campaign = campaignIterator.next();
    // Retrieve the campaign's mobile apps. Retrieving an ad group's mobile
    // apps is similar.
    var appsIterator = campaign.extensions().mobileApps().get();

    while (appsIterator.hasNext()) {
      var apps = appsIterator.next();
      // You can also request reports for pre-defined date ranges. See
      // https://developers.google.com/adwords/api/docs/guides/awql,
      // DateRangeLiteral section for possible values.

      var stats = apps.getStatsFor('LAST_MONTH');
      Logger.log(sitelink.getLinkText() + ', ' + stats.getClicks() + ', ' +
          stats.getImpressions());
    }
  }
}