Skip to content

Commit

Permalink
removed unnecessary query values
Browse files Browse the repository at this point in the history
  • Loading branch information
aaryansinha16 committed Nov 17, 2024
1 parent df7252c commit bcb024b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 72 deletions.
72 changes: 22 additions & 50 deletions packages/channel-google/src/channel-google.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,44 +261,22 @@ class Google implements ChannelInterface {

const videoQuery = `
SELECT
video.id,
video.title,
video.duration_millis,
ad_group_ad.ad.id,
ad_group_ad.ad.name,
ad_group_ad.ad.type,
ad_group_ad.ad.video_responsive_ad.breadcrumb1,
ad_group_ad.ad.video_responsive_ad.breadcrumb2,
ad_group_ad.ad.video_responsive_ad.call_to_actions,
ad_group_ad.ad.video_responsive_ad.companion_banners,
ad_group_ad.ad.video_responsive_ad.descriptions,
ad_group_ad.ad.video_responsive_ad.headlines,
ad_group_ad.ad.video_responsive_ad.long_headlines,
ad_group_ad.ad.video_responsive_ad.videos,
ad_group.id,
ad_group.name,
ad_group.type,
campaign.id,
campaign.name,
campaign.advertising_channel_type,
campaign.advertising_channel_sub_type,
metrics.impressions,
metrics.clicks,
metrics.cost_micros,
metrics.video_quartile_p25_rate,
metrics.video_quartile_p50_rate,
metrics.video_quartile_p75_rate,
metrics.video_quartile_p100_rate,
metrics.video_view_rate,
metrics.video_views,
segments.ad_format_type
FROM video
video.id,
video.title,
video.duration_millis,
ad_group_ad.ad.id,
ad_group_ad.ad.name,
ad_group_ad.ad.video_responsive_ad.call_to_actions,
ad_group.id,
ad_group.name,
campaign.id,
campaign.name,
segments.ad_format_type
FROM video
WHERE segments.date BETWEEN '${formatYYYMMDDDate(range.since)}' AND '${formatYYYMMDDDate(range.until)}'
`;

Expand Down Expand Up @@ -376,6 +354,10 @@ class Google implements ChannelInterface {
externalId: c.asset.id,
adAccountId: dbAccount.id,
name: c.asset.resourceName,
body: el.adGroupAd.ad.videoResponsiveAd?.descriptions[0].text,
title: el.video.title,
callToActionType: el.adGroupAd.ad.videoResponsiveAd?.callToActions[0].text,
imageUrl: c.asset.youtubeVideoAsset?.youtubeVideoId,
}));

creatives.push(...flattenedCreatives);
Expand Down Expand Up @@ -478,8 +460,7 @@ class Google implements ChannelInterface {
customer_client.descriptive_name
FROM
customer_client
WHERE
customer_client.level <= 1
WHERE customer_client.status = 'ENABLED'
`;

const response = await Google.handlePagination(refreshedIntegration, defaultQuery, defaultQueryResponseSchema);
Expand Down Expand Up @@ -706,16 +687,7 @@ class Google implements ChannelInterface {
}

const disConnectIntegrationOnError = async (integrationId: string, error: Error, notify: boolean): Promise<boolean> => {
const metaErrorValidatingAccessTokenChangedSession =
'Error validating access token: The session has been invalidated because the user changed their password or Facebook has changed the session for security reasons.';
const metaErrorNotAuthenticated = 'Error validating access token: The user has not authorized application';
const metaErrorFollowInstructions =
'You cannot access the app till you log in to www.facebook.com and follow the instructions given.';
if (
error.message === metaErrorValidatingAccessTokenChangedSession ||
error.message === metaErrorFollowInstructions ||
error.message.startsWith(metaErrorNotAuthenticated)
) {
if (error.message === 'invalid_token') {
await markErrorIntegrationById(integrationId, notify);
return true;
}
Expand Down
22 changes: 0 additions & 22 deletions packages/channel-google/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const createCommonResponseSchema = <T extends ZodTypeAny>(
};

const videoSchema = z.object({
resourceName: z.string(),
id: z.string(),
durationMillis: z.string().optional(),
title: z.string(),
Expand Down Expand Up @@ -55,11 +54,8 @@ const videoResponsiveAdSchema = z.object({
});

const youtubeAdSchema = z.object({
type: z.string(),
resourceName: z.string(),
videoResponsiveAd: videoResponsiveAdSchema.optional(),
id: z.string(),
name: z.string(),
});

const youtubeAdGroupAdSchema = z.object({
Expand All @@ -68,39 +64,21 @@ const youtubeAdGroupAdSchema = z.object({
});

const adGroupSchema = z.object({
resourceName: z.string(),
type: z.string(),
id: z.string(),
name: z.string(),
});

const campaignSchema = z.object({
resourceName: z.string(),
advertisingChannelType: z.string(),
advertisingChannelSubType: z.string().optional(),
name: z.string(),
id: z.string(),
});

const metricsSchema = z.object({
clicks: z.string(),
videoQuartileP100Rate: z.number().optional(),
videoQuartileP25Rate: z.number().optional(),
videoQuartileP50Rate: z.number().optional(),
videoQuartileP75Rate: z.number().optional(),
videoViewRate: z.number().optional(),
videoViews: z.string(),
costMicros: z.string(),
impressions: z.string(),
});

export const videoAdResponseSchema = createCommonResponseSchema(
z.object({
video: videoSchema,
adGroupAd: youtubeAdGroupAdSchema,
adGroup: adGroupSchema,
campaign: campaignSchema,
metrics: metricsSchema,
}),
);

Expand Down

0 comments on commit bcb024b

Please sign in to comment.