in lib/looker.ts [165:221]
export async function getAndroidCTRPercentData(
id: string,
template: string,
channel?: string,
experiment?: string,
branch?: string,
startDate?: string | null,
endDate?: string | null,
): Promise<CTRData | undefined> {
// XXX the filters are currently defined to match the filters in getDashboard.
// It would be more ideal to consider a different approach when definining
// those filters to sync up the data in both places. Non-trivial changes to
// this code are worth applying some manual performance checking.
// If not using survey template, warn and return undefined since only survey is supported
if (template !== "survey") {
console.warn(
`Warning: Unsupported Android surface "${template}". Only "survey" is currently supported for Android.`,
);
return undefined;
}
// Only proceed with the query for survey template
const queryResult = await runQueryForSurface(
template,
{
"events.normalized_channel": channel,
"events_unnested_table__ping_info__experiments.key": experiment,
"events_unnested_table__ping_info__experiments.value__branch": branch,
"events.sample_id": "to 10", // XXX This is equal to Sample ID <= 10
"events.event_category": "messaging", // XXX this should be updated once we support more Android Looker dashboards
"events_unnested_table__event_extra.value": id.slice(0, -5) + "%",
},
startDate,
endDate,
);
if (queryResult?.length > 0) {
// CTR percents will have 2 decimal places since this is what is expected
// from Experimenter analyses.
const clientCount = queryResult[0]["events.client_count"];
const eventName = clientCount["events.event_name"];
const impressions = eventName["message_shown"];
const primaryRate = queryResult[0].primary_rate;
const ctrPercent = getSafeCtrPercent(primaryRate);
return {
ctrPercent: ctrPercent,
impressions: impressions * 10, // We need to extrapolate real numbers for the 10% sample
};
}
// Return undefined if no query results
return undefined;
}