BLOG

Mobile-Friendly Websites: WordPress, Google Search Console API and RAW

October 18, 2022
   
Solution
Posted by Jeremy Posner

Intro

This is deliberately a short blog post with a SEO flavour. No need to spend much time on saying why your website needs to be mobile-friendly, as 60-70% of all traffic is on small form-factor screens.

But how do you check your site is mobile friendly when content changes often? Can you automate it? and Alert? Now you can 🙂

Google Search Console API has a new ‘experimental’ feature called MobileFriendlyTest/run – we can create a simple function to encapsulate this:

Please note as of November 2022 we have upgraded our language – see our documentation and quick tour for details. These examples below are using previous version of RQL, and will be refactored shortly.

mobile_friendly(url: string) := {

  // structure from GSC API endpoint
  typealias response:= record(
    testStatus: record(status: string),
    mobileFriendliness: string,
    mobileFriendlyIssues: collection(record(rule:string)) nullable
  );
  
  // read endpoint
  READ_JSON[response]("https://searchconsole.googleapis.com/v1/urlTestingTools/mobileFriendlyTest:run?key=xxx-YOUR-KEY-xxxx",
  http_method:="POST",
      http_body_string := print_json ((url:url))
  )
}

Now let’s test, firstly on a ‘good’ web page:

// test 1
mobile_friendly("https://raw-labs.com/")

// returns:
{
  "testStatus": {
    "status": "COMPLETE"
  },
  "mobileFriendliness": "MOBILE_FRIENDLY",
  "mobileFriendlyIssues": null
}

.. and now a web page where GSC tells us we have mobile issues:

// test 2
mobile_friendly("https://raw-labs.com/blog/nyc-taxi-cab-analytics-and-apis-part-3/")

// returns:
{
  "testStatus": {
    "status": "COMPLETE"
  },
  "mobileFriendliness": "NOT_MOBILE_FRIENDLY",
  "mobileFriendlyIssues": [
    {
      "rule": "SIZE_CONTENT_TO_VIEWPORT"
    },
    {
      "rule": "TAP_TARGETS_TOO_CLOSE"
    },
    {
      "rule": "USE_LEGIBLE_FONT_SIZES"
    }
  ]
}

Now we know it works, it’s very simple to iterate over many pages and reformat the results. We are using WordPress, where the pages endpoint gives just that. Take the result field link and feed it into our function above:

SELECT 
  title.rendered, link, modified, mobile_friendly(link) as mobile_result
FROM
 READ("https://raw-labs.com/wp-json/wp/v2/pages")

Here’s what it returns:

[
  {
    "rendered": "Pricing",
    "link": "https://raw-labs.com/pricing/",
    "modified": "2022-10-15T16:39:32.000",
    "mobile_result": {
      "testStatus": {
        "status": "COMPLETE"
      },
      "mobileFriendliness": "MOBILE_FRIENDLY",
      "mobileFriendlyIssues": null
    }
  },
  {
    "rendered": "Resource Library",
    "link": "https://raw-labs.com/library/",
    "modified": "2022-01-18T09:58:18.000",
    "mobile_result": {
      "testStatus": {
        "status": "COMPLETE"
      },
      "mobileFriendliness": "MOBILE_FRIENDLY",
      "mobileFriendlyIssues": null
    }
  },
  {
    "rendered": "Founders Story",
    "link": "https://raw-labs.com/founders-story/",
    "modified": "2022-04-06T07:52:10.000",
    "mobile_result": {
      "testStatus": {
        "status": "COMPLETE"
      },
      "mobileFriendliness": "MOBILE_FRIENDLY",
      "mobileFriendlyIssues": null
    }
  },
  {
    "rendered": "RAW Blog",
    "link": "https://raw-labs.com/blog/",
    "modified": "2022-02-22T12:09:26.000",
    "mobile_result": {
      "testStatus": {
        "status": "COMPLETE"
      },
      "mobileFriendliness": "MOBILE_FRIENDLY",
      "mobileFriendlyIssues": null
    }
  },
  {
    "rendered": "Team",
    "link": "https://raw-labs.com/team/",
    "modified": "2021-07-12T19:39:06.000",
    "mobile_result": {
      "testStatus": {
        "status": "COMPLETE"
      },
      "mobileFriendliness": "MOBILE_FRIENDLY",
      "mobileFriendlyIssues": null
    }
  },
  {
    "rendered": "Careers",
    "link": "https://raw-labs.com/careers/",
    "modified": "2022-01-20T16:26:51.000",
    "mobile_result": {
      "testStatus": {
        "status": "COMPLETE"
      },
      "mobileFriendliness": "MOBILE_FRIENDLY",
      "mobileFriendlyIssues": null
    }
  },
  {
    "rendered": "Your request was received!",
    "link": "https://raw-labs.com/thankyou/",
    "modified": "2021-12-13T17:59:30.000",
    "mobile_result": {
      "testStatus": {
        "status": "COMPLETE"
      },
      "mobileFriendliness": "MOBILE_FRIENDLY",
      "mobileFriendlyIssues": null
    }
  },
  {
    "rendered": "Terms of Use",
    "link": "https://raw-labs.com/terms-of-use/",
    "modified": "2022-03-30T08:20:04.000",
    "mobile_result": {
      "testStatus": {
        "status": "COMPLETE"
      },
      "mobileFriendliness": "MOBILE_FRIENDLY",
      "mobileFriendlyIssues": null
    }
  },
  {
    "rendered": "Privacy Policy",
    "link": "https://raw-labs.com/privacy-policy/",
    "modified": "2022-01-20T12:38:45.000",
    "mobile_result": {
      "testStatus": {
        "status": "COMPLETE"
      },
      "mobileFriendliness": "MOBILE_FRIENDLY",
      "mobileFriendlyIssues": null
    }
  },
  {
    "rendered": "Contact Us",
    "link": "https://raw-labs.com/contact-us/",
    "modified": "2022-10-05T11:20:31.000",
    "mobile_result": {
      "testStatus": {
        "status": "COMPLETE"
      },
      "mobileFriendliness": "MOBILE_FRIENDLY",
      "mobileFriendlyIssues": null
    }
  }
]

Turn this into an API – so that you and others can run it – by signing up for free, and try for yourself. Simple. Check out our other SEO related blogs below too.

Jeremy Posner, VP Product & Solutions


 

Get Started for Free

More Useful Links:

Like this? 

Sign up for our mailing list to receive the latest news and blogs

Learn More

Blog

Powerful new SEO & SEM Data Products with RAW

Create powerful SEO/SEM data products with RAW. This example compares historical search volumes for two keywords / brands over a time period for trend analysis.

Blog

Introducing our Google Cloud API Connector

Our new Google Connector allows many services supported by Google's APIs to be used securely in RAW. Check out an example using Google Search Console, used for SEO and website performance

Blog

Retrieving JSON data from a REST API in Excel with Power Query

Use Excel with Power Query to retrieve data from REST APIs created through RAW in JSON, CSV, or even XML

Blog

Why our Customers chose API delivery for Data Products

We dig into 4 key characterstics of Data Products that our customers cite, and why APIs fit their needs well.

Success

Thank you for your interest. Expect to hear from us soon.

Error

Email address must contain the @ symbol