Alvin Brown provides a tutorial on how to use Verisign DomainScope’s API to produce and store monthly popular keywords for .com and .net domain registrations.
Once upon a time, Verisign provided a monthly email and blog post reporting the top trending keywords contained in recent .com and .net domain registrations for a given month. That all ended circa Q4 2019.
Fortunately, Verisign provides an online interface that gives visitors insight into the top 10 popular keywords for recently registered domains for the last 7, 30, 60 and 90 days or a custom time period.
While this tool is good for the casual observer, it’s not necessarily the same report layout.
But no worries, because I’m sharing with you today a bit of insight and ingenuity using the DomainScope API to create your own database to track top popular keywords on a monthly basis (although you could also take the next step to retrieve daily info if you so desired — hint, hint).
While we’re at it, let me be clear in stating that I’m not diving too deep into the technical weeds on this tutorial — line-by-line detail or characters, or play-by-play commentary, so you’ll have to read between the lines a bit if coding is not your thing.
Nevertheless, I’ve provided a sample file at the very end of this tutorial that should do the trick for you.
But first things first, let’s discuss what’s needed to begin this tutorial. You’ll need to ensure you have the following nearby:
- DomainScope API Documentation
- DomainScope API Account
- Localhost or Web server with PHP/MySQL
Setting up Database and Table for Top Popular Keywords Data
Meeting the bulleted prerequisites, you’re now ready to create a database and table for tracking keyword data.
For this tutorial, I’ve named the database domainscope. The table name is popkeywords and consists of the following columns:
- pkid – column used for auto incremented primary key
- keyword – column used for, you guessed it, the keyword
- total_count – column used to track combined count of .com and .net registrations containing given keyword for given time period
- com_count – column used to track count of .com registrations containing given keyword for given time period
- net_count – column used to track count of .net registrations containing given keyword for given time period
- date – column used for time period
- createDate – column used to track when a table row was inserted or updated
If you’re familiar with MySQL’s command line interface or phpMyAdmin’s SQL feature, then simply copy and paste the following code:
CREATE TABLE `popkeywords` (
`pkid` int(10) UNSIGNED NOT NULL,
`keyword` varchar(255) NOT NULL,
`total_count` int(10) UNSIGNED NOT NULL,
`com_count` int(10) UNSIGNED NOT NULL,
`net_count` int(10) UNSIGNED NOT NULL,
`date` datetime NOT NULL,
`createDate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE `popkeywords`
ADD PRIMARY KEY (`pkid`);
ALTER TABLE `popkeywords`
MODIFY `pkid` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1;
COMMIT;
If you’re not familiar with MySQL’s command line interface or phpMyAdmin, then use the built-in interface provided by your web hosting provider.
When it comes to creating, viewing, and modifying the database and table in phpMyAdmin, SiteGround.com offers good tutorials on getting acclimated with phpMyAdmin.
Connecting to the Database Using PHP Script
Using a text editor of your choice, open and save a .php file named top-popular-keywords-db.php.
Now that you have successfully created a database and table to track keyword results, it’s time to connect to the database using a bit of PHP.
To do so, ensure you have the following information readily available:
- Database hostname
- Database username
- Database password
- Database name
Once aforementioned credentials are properly identified, then define each variable and set their respective values:
$dbhost = ‘’;
$dbuser = ‘’;
$dbpassword = “”;
$dbdatabase = ‘’;
Next, using PHP’s built-in function, mysqli_connect, pass each variable as a comma delimited argument as shown below. Don’t forget to define the $db variable.
$db = mysqli_connect($dbhost,$dbuser,$dbpassword,$dbdatabase);
Next, add the following error checking code should the script not successfully connect to the database when executed. This scripting notifies an error occurred and displays the error to the web page when a connection cannot be successfully made.
if (mysqli_connect_errno())
{
echo “Failed to connect to MySQL: ” . mysqli_connect_error();
}
API Credentials and Variables
Before diving into this section, be sure to have the DomainScope API Documentation handy. You’ll need it.
There are currently seven API methods to provide programmatic access to Verisign DomainScope’s data:
- Pending Delete Search
- Domain Name Registration History
- Domain Name Lookup
- Top Trending Keywords
- Trending Keywords
- Top Popular Keywords
- Popular Keywords
Feel free to dive into each method. As for today, we’ll focus our efforts on Top Popular Keywords method.
While there are no required parameters for the Top Popular Keywords API method, we’ll use the following optional parameters to set the start and end dates respectively: $start_date and $end_date.
Hardcoded variables for start and end dates are provided and commented out (see below). However, it’s best to use dynamic date variables, especially if your plan is to automate script to execute monthly (or daily if you so desire daily keyword information).
Nevertheless, add the code below after the database connection code from the previous section:
// HARDCODED DATES
//$start_date = ‘2020-02-01’;
//$end_date = ‘2020-02-29’;
// DYNAMIC DATES
$start_date = date(“Y-m-d”, strtotime(“first day of previous month”));
$end_date = date(“Y-m-d”, strtotime(“last day of previous month”));
Next, create the API URL request variable, appending the start and end date query string parameters as shown below:
// API URL REQUEST
$url = “https://domainscope.com/api/v2.1/keywords/popularity/top?”;
$url .= “start_date=$start_date&end_date=$end_date”;
Next, define and set DomainScope API credentials using the following code:
// SET KEY CREDENTIALS
$header = array(
‘Accept: application/json’,
‘X-DOMAINSCOPE-APIKEY: XXXXXXXXXXXXXXXXX’
);
NOTE: DON’T FORGET TO REPLACE ‘XXXXXXXXXXXXXXXXX’ WITH YOUR RESPECTIVE DomainScope API Key.
Making API Request to Retrieve Top Popular Keywords Data
I’m not going to bore you with details. In short, the next step is implementing PHP cURL to make the API request to retrieve Top Popular Keywords Data.
One item to pay close attention to is defining the $url variable (see previous section). Copy and paste the code below after the key credentials.
// MAKE CURL CALL
$ch = curl_init();
$timeout=60;
//set the url and other options for curl
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, ‘GET’); // Values: GET, POST, PUT, DELETE, PATCH, UPDATE
//curl_setopt($ch, CURLOPT_POSTFIELDS, $variable);
//curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
//execute call and return response data.
$result = curl_exec($ch);
//close curl connection
curl_close($ch);
Parsing, Tracking, and Displaying Top Popular Keywords Data
Again, I’ll spare you the line-by-line, nitty-gritty details and deep explanation of the code. Just know this section by far is the most critical part of the tutorial because it involves accessing or parsing the API request response data.
First things first, the response data, the json object, needs to be decoded. To do so, use PHP’s built-in json_decode method as shown below:
$dn = json_decode($result, true);
If the aforementioned line of code is not included, then no data can be parsed, tracked in database, or displayed to the web page.
Preparing for the output of data to a web page and into a database table, we’ll make use of a couple of foreach statements combined with the use of three functions (download code to review functions at the end of tutorial):
- checkKeywordData – this function checks to verify keyword and time period exists or does not exist in database
- updateKeywordData – this function updates keyword, total count, .com count, .net count and time period into database
- insertKeywordData – this function inserts keyword, total count, .com count, .net count and time period into database
Copy and paste the code below after the line of code for the $dn variable:
echo “Time Period: $start_date through $end_date.<br>”;
foreach($dn as $keyword){
foreach($keyword as $eachKeyword){
$eachKeyword[‘date’] = $start_date; // set the date as value for keyword and adding to array at date key
echo $eachKeyword[‘keyword’].'<br>’;
// CHECK IF KEYWORD ALREADY EXISTS FOR GIVEN MONTH
$chk_results = checkKeywordData($eachKeyword);
if($chk_results){
// UPDATE EXISTING KEYWORD FOR GIVEN MONTH
$upd_results = updateKeywordData($eachKeyword);
if($upd_results){
echo ‘<b>’.$eachKeyword[‘keyword’].'</b> was updated.<br>’;
} else {
echo ‘<b>’.$eachKeyword[‘keyword’].'</b> was NOT updated.<br>’;
}
} else {
// INSERT KEYWORD FOR GIVEN MONTH
$ins_results = insertKeywordData($eachKeyword);
if($ins_results){
echo ‘<b>’.$eachKeyword[‘keyword’].'</b> was inserted.<br>’;
} else {
echo ‘<b>’.$eachKeyword[‘keyword’].'</b> was NOT inserted.<br>’;
}
}
}
}
NOTE: Don’t forget to add the three functions — download code at the end of this tutorial to review each function.
Accessing Top Popular Keywords Data in Database
At this point in the tutorial, the file you’ve created should be able to connect to a database, make an API call to retrieve top popular keywords data, and insert or update keyword data into a database table.
You’re now ready to execute the code from a web browser. Upon success, the following is displayed in the web browser, or some variation of it:
In the above example, the keyword sentence uses ‘updated’ only because the script had been executed. If it were the script’s first time to execute retrieving data for February time period, then ‘updated’ would read ‘inserted’.
I know the next question is likely, “How do I view previous month or all data at once?” Good question, but it won’t be solved in today’s tutorial.
Nevertheless, easily view all database data when using phpMyAdmin, selecting the database, table and then selecting ‘Browse’ tab. Yes, I know it’s not the best interface, but it is a start and better than nothing. 😉
Closing Thoughts
Well, that does it for today’s tutorial. You should now be able to receive and forever track monthly updates of the top popular keywords for recent .com and .net domain registrations without having to visit DomainScope.com.
I truly hope you’re able to make good use of this tutorial. Don’t forget you can also automate this tutorial using cron jobs.
There are a number of ways this tutorial can be automated and expounded upon to provide greater detail and invaluable insight.
I encourage you to download the tutorial code, create your database, make necessary modifications, and discover where and how far you can this tool.
DOWNLOAD top-popular-keywords.zip for Verisign DomainScope API
Last but not least, please don’t hesitate to leave comments should you have questions or encounter technical challenges implementing this tutorial.
Thanks and that’s all for now!
Seems api is not available any more, it redirects to namestudio.com