如何在 Google Ads API 查询中嵌入自定义滚动日期范围?

发布于 2025-01-10 17:20:00 字数 797 浏览 0 评论 0原文

我正在利用 Google 广告 API 来提取广告系列数据,但遇到一个问题,我想在查询中使用固定日期范围,但它似乎无法作为 文档

这是我的查询:

GAquery = """
SELECT
    segments.date,
    segments.device,
    campaign.name,
    metrics.clicks,
    metrics.conversions,
    metrics.conversions_value,
    metrics.cost_micros,
    metrics.impressions
FROM
   campaign WHERE segments.date DURING LAST_30_DAYS
ORDER BY
    metrics.clicks DESC"""

# Issues a search request using streaming.
response = ga_service.search_stream(customer_id=customer_id, query=GAquery)

我希望获取 LAST_60_DAYS 而不是 30,但将 LAST_30_DAYS 更改为 LAST_60_DAYS 错误。有没有人找到一种方法来编码不是系统中预设选项的滚动日期范围,或者我们是否只使用预设选项?

非常感谢您的帮助。 :)

I am utilizing the Google ads API to pull campaign data and I am having an issue where I would like to use a fixed date range in my query, but it seems to be unavailable as an option in the documentation.

Here is my query:

GAquery = """
SELECT
    segments.date,
    segments.device,
    campaign.name,
    metrics.clicks,
    metrics.conversions,
    metrics.conversions_value,
    metrics.cost_micros,
    metrics.impressions
FROM
   campaign WHERE segments.date DURING LAST_30_DAYS
ORDER BY
    metrics.clicks DESC"""

# Issues a search request using streaming.
response = ga_service.search_stream(customer_id=customer_id, query=GAquery)

I am looking to get the LAST_60_DAYS instead of 30, but changing the LAST_30_DAYS to LAST_60_DAYS errors out. Has anyone found a way to code a rolling date range that is not a preset option in the system or are we stuck with only the preset options?

Thanks so much for your help. :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

十雾 2025-01-17 17:20:00

您链接到的预定义日期范围是唯一存在的。

如果您需要与可用选项不同的时间范围,则必须自行计算开始日期和结束日期,并使用带有 segments.date BETWEEN '' 的自定义日期范围AND“

The predefined date ranges you linked to are the only ones that exist.

If you need a different time range than the available options, you're going to have to calculate the start and end dates yourself and use a custom date range with segments.date BETWEEN '<START_DATE>' AND '<END_DATE>'.

七堇年 2025-01-17 17:20:00

只需自己创建变量名称并将它们插入到查询中即可。

from datetime import datetime, timedelta
sixty_days_ago = datetime.now().date() + timedelta(days=60)
now = datetime.now().date()

然后在您的查询中:

GAquery = f"""
SELECT
    segments.date,
    segments.device,
    campaign.name,
    metrics.clicks,
    metrics.conversions,
    metrics.conversions_value,
    metrics.cost_micros,
    metrics.impressions
FROM
   campaign WHERE segments.date BETWEEN {sixty_days_ago} AND {now}
ORDER BY
    metrics.clicks DESC"""

Simply create the variable names yourself and insert them into the query.

from datetime import datetime, timedelta
sixty_days_ago = datetime.now().date() + timedelta(days=60)
now = datetime.now().date()

Then in your query:

GAquery = f"""
SELECT
    segments.date,
    segments.device,
    campaign.name,
    metrics.clicks,
    metrics.conversions,
    metrics.conversions_value,
    metrics.cost_micros,
    metrics.impressions
FROM
   campaign WHERE segments.date BETWEEN {sixty_days_ago} AND {now}
ORDER BY
    metrics.clicks DESC"""
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文