mirror of
https://github.com/towfiqi/serpbear
synced 2025-06-26 18:15:54 +00:00
fix double entrees in Discover Tab (Google Search Console)
This commit is contained in:
parent
6aa8900577
commit
3a05703921
@ -32,6 +32,40 @@ const DiscoverPage: NextPage = () => {
|
||||
const theDomains: DomainType[] = (domainsData && domainsData.domains) || [];
|
||||
const theKeywords: SearchAnalyticsItem[] = keywordsData?.data && keywordsData.data[scDateFilter] ? keywordsData.data[scDateFilter] : [];
|
||||
|
||||
const theKeywordsCount = theKeywords.reduce<Map<string, number>>((r, o) => {
|
||||
const key = `${o.device}-${o.country}-${o.keyword}`;
|
||||
const item = r.get(key) || 0;
|
||||
return r.set(key, item + 1);
|
||||
}, new Map()) || [];
|
||||
|
||||
const theKeywordsGrouped : SearchAnalyticsItem[] = [...theKeywords.reduce<Map<string, SearchAnalyticsItem>>((r, o) => {
|
||||
const key = `${o.device}-${o.country}-${o.keyword}`;
|
||||
|
||||
const item = r.get(key) || { ...o,
|
||||
...{
|
||||
clicks: 0,
|
||||
impressions: 0,
|
||||
ctr: 0,
|
||||
position: 0,
|
||||
},
|
||||
};
|
||||
item.clicks += o.clicks;
|
||||
item.impressions += o.impressions;
|
||||
item.ctr = o.ctr + item.ctr;
|
||||
item.position = o.position + item.position;
|
||||
|
||||
return r.set(key, item);
|
||||
}, new Map()).values()].map<SearchAnalyticsItem>((o: SearchAnalyticsItem) => {
|
||||
const key = `${o.device}-${o.country}-${o.keyword}`;
|
||||
const count = theKeywordsCount?.get(key) || 0;
|
||||
return { ...o,
|
||||
...{
|
||||
ctr: o.ctr / count,
|
||||
position: o.position / count,
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
const activDomain: DomainType|null = useMemo(() => {
|
||||
let active:DomainType|null = null;
|
||||
if (domainsData?.domains && router.query?.slug) {
|
||||
@ -62,7 +96,7 @@ const DiscoverPage: NextPage = () => {
|
||||
domains={theDomains}
|
||||
showAddModal={() => console.log('XXXXX')}
|
||||
showSettingsModal={setShowDomainSettings}
|
||||
exportCsv={() => exportCSV(theKeywords, activDomain.domain, scDateFilter)}
|
||||
exportCsv={() => exportCSV(theKeywordsGrouped, activDomain.domain, scDateFilter)}
|
||||
scFilter={scDateFilter}
|
||||
setScFilter={(item:string) => setSCDateFilter(item)}
|
||||
/>
|
||||
@ -71,7 +105,7 @@ const DiscoverPage: NextPage = () => {
|
||||
<SCKeywordsTable
|
||||
isLoading={keywordsLoading || isFetching}
|
||||
domain={activDomain}
|
||||
keywords={theKeywords}
|
||||
keywords={theKeywordsGrouped}
|
||||
isConsoleIntegrated={scConnected || domainHasScAPI}
|
||||
/>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user