mirror of
https://github.com/towfiqi/serpbear
synced 2025-06-26 18:15:54 +00:00
- Integrates Google Adwords API to generate keywords for a domain. - Adds a New Adwords Integration ui inside the App settings > Integrations screen to integrate Google Adwords. - Adds a New Ideas tab under each domain. - Adds ability to automatically generate keyword ideas based on website content, currently tracked keywords, Currently Ranking keywords or custom keywords - The Keyword Ideas are not saved in database, they are saved in a local file inside the data folder. File naming convention: IDEAS_domain.com.json - The keywords can be marked as favorites, and each time a keyword is favorited, they are added in the IDEAS_domain.com.json file.
63 lines
2.9 KiB
TypeScript
63 lines
2.9 KiB
TypeScript
import countries from '../countries';
|
|
|
|
/**
|
|
* Generates CSV File form the given domain & keywords, and automatically downloads it.
|
|
* @param {KeywordType[]} keywords - The keywords of the domain
|
|
* @param {string} domain - The domain name.
|
|
* @returns {void}
|
|
*/
|
|
const exportCSV = (keywords: KeywordType[] | SCKeywordType[], domain:string, scDataDuration = 'lastThreeDays') => {
|
|
const isSCKeywords = !!(keywords && keywords[0] && keywords[0].uid);
|
|
let csvHeader = 'ID,Keyword,Position,URL,Country,Device,Updated,Added,Tags\r\n';
|
|
let csvBody = '';
|
|
let fileName = `${domain}-keywords_serp.csv`;
|
|
|
|
console.log(keywords[0]);
|
|
console.log('isSCKeywords:', isSCKeywords);
|
|
|
|
if (isSCKeywords) {
|
|
csvHeader = 'ID,Keyword,Position,Impressions,Clicks,CTR,Country,Device\r\n';
|
|
fileName = `${domain}-search-console-${scDataDuration}.csv`;
|
|
keywords.forEach((keywordData, index) => {
|
|
const { keyword, position, country, device, clicks, impressions, ctr } = keywordData as SCKeywordType;
|
|
// eslint-disable-next-line max-len
|
|
csvBody += `${index}, ${keyword}, ${position === 0 ? '-' : position}, ${impressions}, ${clicks}, ${ctr}, ${countries[country][0]}, ${device}\r\n`;
|
|
});
|
|
} else {
|
|
keywords.forEach((keywordData) => {
|
|
const { ID, keyword, position, url, country, device, lastUpdated, added, tags } = keywordData as KeywordType;
|
|
// eslint-disable-next-line max-len
|
|
csvBody += `${ID}, ${keyword}, ${position === 0 ? '-' : position}, ${url || '-'}, ${countries[country][0]}, ${device}, ${lastUpdated}, ${added}, ${tags.join(',')}\r\n`;
|
|
});
|
|
}
|
|
|
|
downloadCSV(csvHeader, csvBody, fileName);
|
|
};
|
|
|
|
export const exportKeywordIdeas = (keywords: IdeaKeyword[], domainName:string) => {
|
|
const csvHeader = 'Keyword,Volume,Competition,CompetitionScore,Country,Added\r\n';
|
|
let csvBody = '';
|
|
const fileName = `${domainName}-keyword_ideas.csv`;
|
|
keywords.forEach((keywordData) => {
|
|
const { keyword, competition, country, domain, competitionIndex, avgMonthlySearches, added, updated, position } = keywordData;
|
|
// eslint-disable-next-line max-len
|
|
const addedDate = new Intl.DateTimeFormat('en-US').format(new Date(added));
|
|
csvBody += `${keyword}, ${avgMonthlySearches}, ${competition}, ${competitionIndex}, ${countries[country][0]}, ${addedDate}\r\n`;
|
|
});
|
|
downloadCSV(csvHeader, csvBody, fileName);
|
|
};
|
|
|
|
const downloadCSV = (csvHeader:string, csvBody:string, fileName:string) => {
|
|
const blob = new Blob([csvHeader + csvBody], { type: 'text/csv;charset=utf-8;' });
|
|
const url = URL.createObjectURL(blob);
|
|
const link = document.createElement('a');
|
|
link.setAttribute('href', url);
|
|
link.setAttribute('download', fileName);
|
|
link.style.visibility = 'hidden';
|
|
document.body.appendChild(link);
|
|
link.click();
|
|
document.body.removeChild(link);
|
|
};
|
|
|
|
export default exportCSV;
|