Hello everyone, if you do internet marketing, you probably have to deal with a lot of advertising services every day and at least one web analytics platform, if you need to at least once a month, or maybe even once a week with your hands to compile data on expenses, and other statistical information from all sources is fraught with not only large time costs, but also the probability of error when consolidating data from many sources in manual mode is quite large. In this article I’ll give you tips on ready-made extensions (packages) for the R language, with which you can automate the process of collecting data from most popular advertising systems and web analytics platforms.
Since In this article we are talking about the R language, then you will need R itself and the RStudio development environment.
Both the R language and RStudio are free, free software, so you can freely download them from official sites.
There is nothing difficult to get started with R packages, this is done as follows:
install.packages
command;library
or require
command.The difference between library
and require
is only that the library
will generate an error if you try to connect a package that you have not installed, and require
in the same case just shows a warning, while the script will continue.
To install the GitHub packages described in this article, you first need to install the devtools package, to do this, run the install.packages("devtools")
.
In the course of reading this article, you may have a question from which repository it is better to install one or another package, in fact, on GitHub, as a rule, the most current dev versions of packages from developers, They have all the new features that may not be in the version of the package that is available on CRAN, but, accordingly, the dev version may not be sufficiently tested at the time of loading and contain errors.
The version on CRAN is carefully checked by a team of specialists before it is downloaded, and must comply with all the requirements of this repository policy. If you download a package from CRAN, you can be sure that it will not harm your data in any way and will not create any incomprehensible files on your computer without your permission. PC etc.
In fact, you only need to understand the subject area of Internet marketing, no programming skills are required in this case, because we will talk about ready-made packages, using functions from which you can automate the ruined part of your work.
The article will not have a detailed description of how to work with each function of the packages in question, since such an article would be too long, but I will describe the capabilities of each package, give a list of the main functions that you need, as well as give a link to the official documentation, with which you can already deal in most detail with all the functions available in one package or another. . In addition to each package, I will give a small sample of the code, so that you would have a clearer syntax.
Installing the package from GitHub: devtools::install_github("selesnow/ryandexdirect")
Official documentation: link
This package is designed to work with the API of one of the most popular advertising sites in the CIS - Yandex.Direct.
The main functions available in ryandexdirect that you may need to work with the Yandex.Direct API:
yadirAuth
- API authorization;yadirGetAds
, yadirGetCampaignList
, yadirGetKeyWords
- Download a list of ads, ad campaigns, keywords;yadirGetReport
- Download statistics from Yandex.Direct.yadirGetDictionary
- Download reference information.yadirStartAds
, yadirStartCampaigns
, yadirStartKeyWords
- library(ryandexdirect) stat <- yadirGetReport(ReportType = "ACCOUNT_PERFORMANCE_REPORT", DateRangeType = "CUSTOM_DATE", DateFrom = "2018-01-01", DateTo = "2018-05-10", FieldNames = c("AdNetworkType", "Impressions", "Clicks", "Cost"), FilterList = c("CampaignId IN 123456 ,987654","Clicks GREATER_THAN 100"), IncludeVAT = "YES", IncludeDiscount = "NO", Login = " ", TokenPath = "C:/token_yandex")
More details about each argument can be found in the official ryandexdirect or Yandex.Direct API Reports service .
Installing a package with CRAN: install.packages("RAdwords")
Installing the package from GitHub: devtools::install_github("jburkhardt/RAdwords")
Official documentation: link
The main feature of this package is to authorize the Google Ads API and download statistics from all reports available on this interface.
In fact, the package basically contains not very many functions, but I have used only three of them all the time:
doAuth
- Authorization;statement
- Formation of the request body to the API;getData
- Download data from API. library(RAdwords) # adw_token <- doAyth() # body <- statement(select=c('AccountDescriptiveName', 'ExternalCustomerId', 'AccountCurrencyCode', 'AdNetworkType1', 'RegionCriteriaId', 'CountryCriteriaId', 'CityCriteriaId', 'Device', 'Month', 'Year', 'Impressions', 'Clicks', 'Interactions', 'VideoViews', 'Cost', 'Conversions' ), report="GEO_PERFORMANCE_REPORT", start="2018-09-01", end="2018-09-20") my_data <- getData(clientCustomerId = "000-000-0000", google_auth = adw_token , statement = body, transformation = T)
The list of reports available in the Google Ads API and fields can be found at the link in the official help.
Installing a package with CRAN: install.packages("adwordsR")
Installing a package from GitHub: devtools::install_github("cran/adwordsR")
The adwordsR package is similar in meaning to RAdwords, but it is newer and has a much larger set of functions.
In addition to the features of the RAdwords package described above, adwordsR gives you ample opportunities to work with TargetingIdeaService, the service with which you can get targeting options directly from a tool or platform that helps automate account optimization.
generateAdwordsToken
- Request a token to work with the Google Ads API;loadAdwordsToken
- Load the requested and previously saved token;getReportData
- Download statistics from your Google Ads account. library(adwordsR) # adw_token <- generateAdwordsToken(saveNewToken = TRUE, addGitignore = FALSE) # adw_token <- loadAdwordsToken() # AdWordsData <- getReportData(reportType = "CAMPAIGN_PERFORMANCE_REPORT", startDate = "2018-08-01", endDate = "2018-08-15", clientCustomerId = "000-000-0000", credentials = adw_token, attributes = "CampaignName,CampaignStatus", segment = "Date,AdNetworkType1", metrics = "AverageCost,Clicks,Conversions", includeZeroImpressions = TRUE, useRequestedHeaders = FALSE)
Installing a package with CRAN: install.packages("rfacebookstat")
Installing the package from GitHub: devtools::install_github("selesnow/rfacebookstat")
Official documentation: link
fbGetToken
- Authorization in the Facebook API;fbGetBusinessManagers
- Download a list of business manager;fbGetAdAccounts
- Download a list of advertising accounts;fbGetCampaigns
, fbGetAds
, fbGetAdSets
- Download a list of ad campaigns, ads and ad groups;fbGetMarketingStat
- Download statistics from advertising accounts Facebook. library(rfacebookstat) token <- fbGetToken(app_id = 00000000000000) fb_data <- fbGetMarketingStat(accounts_id = "act_00000000000000", level = "campaign", fields = "campaign_name,actions", action_breakdowns = "action_link_click_destination", date_start = "2017-11-01", date_stop = "2017-11-20", interval = "day", access_token = token)
Installing the package from GitHub: devtools::install_github("selesnow/rvkstat")
Official documentation: link
Enough powerful and multi-functional package for working with the API of the social network Vkontakte.
The rvkstat package at the time of this writing contains more than 30 functions, here are the most useful ones:
vkAuth
- Authorization;vkGetAdStatistics
- Download statistics from the advertising vkGetAdStatistics
;vkGetAdCampaigns
, vkGetAds
- Download a list of advertising campaigns and ads;vkGetGroupStat
- Download statistics on visiting groups and communities Vkontakte. library(rvkstat) my_tok <- vkAuth(app_id = 111,app_secret = "efbscuyewb7cb4ru4bj") # camp <- vkGetAdCampaigns(account_id = 1, access_token = my_tok$access_token) # vk_stat_by_campaign <- vkGetAdStatistics(account_id = 1, ids_type = "campaign", ids = camp$id , period = "day", date_from = "2010-01-01", date_to = "2017-09-10", access_token = my_tok$access_token)
Installing a package with CRAN: install.packages("rmytarget")
Installing the package from GitHub: devtools::install_github("selesnow/rmytarget")
Official documentation: link
myTarAuth
- Authorization;myTarGetAdList
, myTarGetCampaignList
- Download a list of ads and ad campaigns;myTarGetStats
- Download statistics for ads and advertising campaigns. library(rmytarget) # Ads <- myTarGetAdList(login = " ") # a_stat <- myTarGetStats(date_from = "2016-08-01", date_to = "2016-08-10", object_type = "banners", object_id = Ads$id, stat_type = "day", login = " ")
Installing a package with CRAN: install.packages("rym")
Installing the package from GitHub: devtools::install_github("selesnow/rym")
Official documentation: link
The rym package allows you to work with all APIs available in Yandex.Metrica:
rym_auth
- Authorization;rym_get_counters
- Download the list of counters Yandex.Metrica;rym_get_data
- Load data from the API reports;rym_get_ga
- Download data from API compatible with Google Analytics Core API;rym_get_logs
- Download raw data from Logs API. reporting.api.stat <- rym_get_data(counters = "00000000,111111111", date.from = "2018-08-01", date.to = "yesterday", dimensions = "ym:s:date,ym:s:lastTrafficSource", metrics = "ym:s:visits,ym:s:pageviews,ym:s:users", filters = "ym:s:trafficSourceName==' ' AND ym:s:isNewUser=='Yes'", sort = "-ym:s:date", accuracy = "full", login = " ", token.path = "metrica_token", lang = "ru")
So, using the packages in this article, you can easily automate the collection of data from such sources as Yandex.Direct, Google Ads, Facebook, Vkontakte, MyTarget and Yandex.Metrica. Of course, this is far from an exhaustive list of services that are used by marketing specialists, but it’s quite difficult to fit all the tools into one article, so if this article gets positive reviews, I’ll write a sequel.
Further, the obtained data can be converted using the dplyr
package, and recorded in various databases using the DBI interface, but these are already quite voluminous topics for the following articles.
If you also have interesting packages in your arsenal that can help automate data collection from advertising sources or web analytic platforms, leave them in the comments to this article.
Source: https://habr.com/ru/post/425425/
All Articles