Opteo / google-ads-api

Google Ads API client library for Node.js
https://opteo.com
MIT License
270 stars 90 forks source link

Date Ranges Options #408

Closed ahmarif closed 2 years ago

ahmarif commented 2 years ago

Does your package offer a date range such as Yesterday or Last 30 Days? I can see 'from' and 'to' for dates.

const campaigns = await customer.report({
          entity: "campaign",
          attributes: ['campaign.name'],

          metrics: [
            "metrics.cost_micros",
            "metrics.clicks",
            "metrics.impressions",
            "metrics.all_conversions",
          ],

          order: [
            { field: "campaign.id" } // default sort_order is descending
          ],

        from_date:starting_date,

        to_date:ending_date,

        constraints: {
           'campaign.name': campaignName,

        },

        });
kritzware commented 2 years ago

Yes, you can use the field date_constant instead of from_date and to_date for this.

ahmarif commented 2 years ago

so this is date_constant : yesterday?

kritzware commented 2 years ago

Exactly, but remember to keep the values identical to those described in the Google Ads documentation

const campaigns = await customer.report({
    entity: 'campaign',
    attributes: ['campaign.name'],
    metrics: [
        'metrics.cost_micros',
        'metrics.clicks',
        'metrics.impressions',
        'metrics.all_conversions',
    ],
    date_constant: 'YESTERDAY'
})
ahmarif commented 2 years ago

Ok got it. That was very helpful.