Lo-Fi Python

Oct 30, 2021

WordPress Ad Campaign Results from a Typical Blog

In September 2021, I tested out the recommended ads runner, WordAds, on this WordPress blog. 6,182 ads were served over the course of a month, earning $0.86 from impressions and clicks. My average CPM or cost per thousand impressions was $0.14. My blog averages about 1,600 views a month at the moment, mostly fueled by various search engines. Here's an example of one ad that ran:

**Example Ad Run on This Site Shown Above**

Example Ad Run on This Site Shown Above

In my WordPress account, I upgraded to the business plan. This gave me access to WordPress plug-ins. I enabled the Yoast SEO plug-in and activated its site optimization. I also enabled the maximum ads possible in my settings. In spite of these efforts, the results were sparse. Maybe there's more that I could have done. But this blog is passive and more like a hobby at the moment. I'm ok with a blog that makes $0.86 per month. Maybe someday it will be worth more. But I enjoy writing so it's all good. My skills grow and maybe I share something with someone across the world. That's what keeps me coming back.

I concluded I will not be running ads anytime soon. I wanted to get a baseline of what I was leaving on the table by not running ads. Now I can project when I might tap into the blog's potential traffic revenue, if ever. It seems I would need much higher views per month before ads makes sense with my level of traffic, 65 blog followers and minor social media clout.

There's also the added benefit of not serving up people's data to ad companies. Ads seem to be a generally accepted way to earn from your internet labors. But right now, they're not for this blog. Good luck monetizing your blog. Or just writing for the hell of it!

Wordpress Ad Campaign Analytics

Sep 06, 2021

Yoast SEO API Python Example With requests + pandas

Lately I've been checking out the Yoast SEO plug-in and their REST API. The API returns all of the SEO metadata, meta tags, schema.org data, etc. for your Wordpress blog posts. Here's a Yoast API Python example script to fetch post metadata via requests and pandas:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
import pandas as pd
import requests

def fetch_metadata(post_url):
    """Returns the Yoast API response as pandas dataframe."""
    url = f'https://atomic-temporary-107329037.wpcomstaging.com/wp-json/yoast/v1/get_head?url={post_url}'
    r = requests.get(url)
    print(r.text)
    print(r.status_code)
    response_dict = r.json()
    metadata_df = pd.json_normalize(response_dict['json'])
    return metadata_df

url = 'https://github.com/erickbytes/Python-Marketer-Reader-Analytics/blob/master/dataset/2020_pythonmarketer.com_post_views.xlsx?raw=true.xlsx'
posts = pd.read_excel(url)
# update url domain with pandas .str accessor
posts.url = posts.url.str.replace(pat='.wordpress', repl='', regex=False)
posts['metadata'] = posts.url.apply(fetch_metadata)
metadata_df = pd.concat(list(posts['results']))
metadata_df.to_csv('Wordpress Blog Post Yoast API Metadata.csv', index=False)

What this script is doing:

  1. Read a list of my blog posts from Github into a pandas dataframe.
  2. Use pandas .apply to fetch the metadata for each post url.
  3. Deserialize + normalize the JSON response.
  4. Convert to a pandas dataframe and store in a pandas Series named 'metadata'.
  5. Merge the series and write the metadata to a csv file.

The Payoff:

You'll end up with blobs of JSON formatted metadata to sift through or wrangle to your liking! Check out the Yoast documentation if you're interested in finding out more about their APIs.

New to APIs?

It's ok if so, we all were once. Check out my guide to making HTTP requests with Python if you want to see more API examples.

SEO Overview