Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default {
key: "google_ads-add-contact-to-list-by-email",
name: "Add Contact to Customer List by Email",
description: "Adds a contact to a specific customer list in Google Ads. Lists typically update in 6 to 12 hours after operation. [See the documentation](https://developers.google.com/google-ads/api/docs/remarketing/audience-segments/customer-match/get-started)",
version: "0.1.0",
version: "0.1.1",
type: "action",
props: {
...common.props,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default {
name: "Create Customer List",
description:
"Create a new customer list in Google Ads. [See the documentation](https://developers.google.com/google-ads/api/rest/reference/rest/v16/UserList)",
version: "0.0.1",
version: "0.0.2",
type: "action",
props: {
...common.props,
Expand Down
55 changes: 55 additions & 0 deletions components/google_ads/actions/create-report/common-constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
export const DATE_RANGE_OPTIONS = [
{
value: "CUSTOM",
label: "Specify a custom date range",
},
{
value: "TODAY",
label: "Today only",
},
{
value: "YESTERDAY",
label: "Yesterday only",
},
{
value: "LAST_7_DAYS",
label: "The last 7 days not including today",
},
{
value: "LAST_BUSINESS_WEEK",
label:
"The 5 day business week, Monday through Friday, of the previous business week",
},
{
value: "THIS_MONTH",
label: "All days in the current month",
},
{
value: "LAST_MONTH",
label: "All days in the previous month",
},
{
value: "LAST_14_DAYS",
label: "The last 14 days not including today",
},
{
value: "LAST_30_DAYS",
label: "The last 30 days not including today",
},
{
value: "THIS_WEEK_SUN_TODAY",
label: "The period between the previous Sunday and the current day",
},
{
value: "THIS_WEEK_MON_TODAY",
label: "The period between the previous Monday and the current day",
},
{
value: "LAST_WEEK_SUN_SAT",
label: "The 7-day period starting with the previous Sunday",
},
{
value: "LAST_WEEK_MON_SUN",
label: "The 7-day period starting with the previous Monday",
},
];
126 changes: 113 additions & 13 deletions components/google_ads/actions/create-report/create-report.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { ad } from "../../common/resources/ad.mjs";
import { campaign } from "../../common/resources/campaign.mjs";
import { customer } from "../../common/resources/customer.mjs";
import { ConfigurationError } from "@pipedream/platform";
import { DATE_RANGE_OPTIONS } from "./common-constants.mjs";
import { checkPrefix } from "../../common/utils.mjs";

const RESOURCES = [
adGroup,
Expand All @@ -17,7 +19,7 @@ export default {
key: "google_ads-create-report",
name: "Create Report",
description: "Generates a report from your Google Ads data. [See the documentation](https://developers.google.com/google-ads/api/fields/v16/overview)",
version: "0.0.2",
version: "0.1.0",
type: "action",
props: {
...common.props,
Expand All @@ -43,26 +45,79 @@ export default {
alertType: "info",
content: `[See the documentation](https://developers.google.com/google-ads/api/fields/v16/${value}) for more information on available fields, segments and metrics.`,
},
objectFilter: {
type: "string[]",
label: `Filter by ${label}s`,
description: `Select the ${label}s to generate a report for (or leave blank for all ${label}s)`,
optional: true,
useQuery: true,
options: async ({
query, prevContext: { nextPageToken: pageToken },
}) => {
const {
accountId, customerClientId, resource,
} = this;
const {
results, nextPageToken,
} = await this.googleAds.listResources({
accountId,
customerClientId,
resource,
query,
pageToken,
});
const options = results?.map?.((item) => this.getResourceOption(item, resource));
return {
options,
context: {
nextPageToken,
},
};
},
},
dateRange: {
type: "string",
label: "Date Range",
description: "Select a date range for the report",
options: DATE_RANGE_OPTIONS,
optional: true,
reloadProps: true,
},
...(this.dateRange === "CUSTOM" && {
startDate: {
type: "string",
label: "Start Date",
description: "The start date, in `YYYY-MM-DD` format",
},
endDate: {
type: "string",
label: "End Date",
description: "The end date, in `YYYY-MM-DD` format",
},
}),
fields: {
type: "string[]",
label: "Fields",
description: `${label} data fields to obtain`,
description: "Select any fields you want to include in your report.",
options: resource.fields,
optional: true,
reloadProps: true,
},
segments: {
type: "string[]",
label: "Segments",
description: `${label} segments to obtain [more info on the documentation](https://developers.google.com/google-ads/api/fields/v16/segments)`,
description: "Select any segments you want to include in your report. See the documentation [here](https://developers.google.com/google-ads/api/fields/v16/segments)",
options: resource.segments,
default: [
"segments.date",
],
optional: true,
reloadProps: true,
},
metrics: {
type: "string[]",
label: "Metrics",
description: `${label} metrics to obtain [more info on the documentation](https://developers.google.com/google-ads/api/fields/v16/metrics)`,
description: "Select any metrics you want to include in your report. See the documentation [here](https://developers.google.com/google-ads/api/fields/v16/metrics)",
options: resource.metrics,
optional: true,
reloadProps: true,
Expand Down Expand Up @@ -114,26 +169,71 @@ export default {
};
},
methods: {
getResourceOption(item, resource) {
let label, value;
switch (resource) {
case "campaign":
label = item.campaign.name;
value = item.campaign.id;
break;

case "customer":
label = item.customer.descriptiveName;
value = item.customer.id;
break;

case "ad_group":
label = item.adGroup.name;
value = item.adGroup.id;
break;

case "ad_group_ad":
label = item.adGroupAd.ad.name;
value = item.adGroupAd.ad.id;
break;
}

return {
label,
value,
};
},
buildQuery() {
const {
resource, limit, orderBy, direction,
resource, fields, segments, metrics, limit, orderBy, direction, objectFilter, dateRange,
} = this;
const fields = this.fields?.map((i) => `${resource}.${i}`) ?? [];
const segments = this.segments?.map((i) => `segments.${i}`) ?? [];
const metrics = this.metrics?.map((i) => `metrics.${i}`) ?? [];

const filteredSegments = dateRange
? segments
: segments?.filter((i) => i !== "segments.date");

const selection = [
...fields,
...segments,
...metrics,
...checkPrefix(fields, resource),
...checkPrefix(filteredSegments, "segments"),
...checkPrefix(metrics, "metrics"),
];

if (!selection.length) {
throw new ConfigurationError("Select at least one field, segment or metric.");
}

let query = `SELECT ${selection.join(", ")} FROM ${resource}`;
if (objectFilter) {
query += ` WHERE ${resource === "ad_group_ad"
? "ad_group_ad.ad"
: resource}.id IN (${objectFilter.join?.(", ") ?? objectFilter})`;
}
if (dateRange) {
const dateClause = dateRange === "CUSTOM"
? `BETWEEN '${this.startDate}' AND '${this.endDate}'`
: `DURING ${dateRange}`;
query += ` ${objectFilter
? "AND"
: "WHERE"} segments.date ${dateClause}`;
}

if (orderBy && direction) {
query += ` ORDER BY ${`${resource}.${orderBy}`} ${direction}`;
query += ` ORDER BY ${orderBy} ${direction}`;
}
if (limit) {
query += ` LIMIT ${limit}`;
Expand All @@ -155,7 +255,7 @@ export default {

const { length } = results;

$.export("$summary", `Sucessfully obtained ${length} result${length === 1
$.export("$summary", `Successfully obtained ${length} result${length === 1
? ""
: "s"}`);
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default {
key: "google_ads-send-offline-conversion",
name: "Send Offline Conversion",
description: "Send an event from to Google Ads to track offline conversions. [See the documentation](https://developers.google.com/google-ads/api/rest/reference/rest/v16/ConversionAction)",
version: "0.0.1",
version: "0.0.2",
type: "action",
props: {
...common.props,
Expand Down
20 changes: 18 additions & 2 deletions components/google_ads/common/queries.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function listCampaigns({
const defaultFields = [
"id",
"name",
];
].map((s) => `campaign.${s}`);
if (typeof fields === "string") {
fields = fields.split(",").map((s) => s.trim());
}
Expand All @@ -91,7 +91,22 @@ function listCampaigns({
? ` WHERE ${savedIds.map((id) => `campaign.id != ${id}`).join(" AND ")}`
: "";

return `SELECT ${fields.map((s) => `campaign.${s}`).join(", ")} FROM campaign${filter}`;
return `SELECT ${fields.join(", ")} FROM campaign${filter}`;
}

function listResources(resource, query) {
const name = resource === "customer"
? "descriptive_name"
: "name";
const fieldResource = resource === "ad_group_ad"
? "ad_group_ad.ad"
: resource;

let result = `SELECT ${fieldResource}.id, ${fieldResource}.${name} FROM ${resource}`;
if (query) {
result += ` WHERE ${fieldResource}.${name} LIKE '%${query}%'`;
}
return result;
}

export const QUERIES = {
Expand All @@ -101,5 +116,6 @@ export const QUERIES = {
listLeadForms,
listLeadFormSubmissionData,
listRemarketingActions,
listResources,
listUserLists,
};
14 changes: 5 additions & 9 deletions components/google_ads/common/resources/ad.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { getOption } from "../utils.mjs";

const fields = [
"action_items",
"ad.added_by_google_ads",
Expand Down Expand Up @@ -213,7 +215,7 @@ const fields = [
"primary_status_reasons",
"resource_name",
"status",
];
].map((f) => getOption(f, "ad_group_ad"));

const segments = [
"ad_destination_type",
Expand All @@ -226,20 +228,14 @@ const segments = [
"conversion_lag_bucket",
"conversion_or_adjustment_lag_bucket",
"date",
"day_of_week",
"device",
"external_conversion_source",
"keyword.ad_group_criterion",
"keyword.info.match_type",
"keyword.info.text",
"month",
"month_of_year",
"new_versus_returning_customers",
"quarter",
"slot",
"week",
"year",
];
].map((f) => getOption(f, "segments"));

const metrics = [
"absolute_top_impression_percentage",
Expand Down Expand Up @@ -319,7 +315,7 @@ const metrics = [
"video_view_rate",
"video_views",
"view_through_conversions",
];
].map((f) => getOption(f, "metrics"));

const resourceOption = {
label: "Ad",
Expand Down
Loading