Created
September 30, 2018 21:42
-
-
Save abfo/77293f726cd9440118ced9bcb10d5ef4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var urlToMonitor = ''; | |
| var alertEmail = ''; | |
| var runTestKey = ''; | |
| var runTestUrl = 'https://searchconsole.googleapis.com/v1/urlTestingTools/mobileFriendlyTest:run?key='; | |
| function mobileFriendlyMonitor() { | |
| try { | |
| var postBody = { | |
| 'url' : urlToMonitor | |
| }; | |
| var options = { | |
| 'method' : 'post', | |
| 'contentType': 'application/json', | |
| 'payload' : JSON.stringify(postBody) | |
| }; | |
| var response = UrlFetchApp.fetch(runTestUrl + runTestKey, options); | |
| var json = response.getContentText(); | |
| var mobileFriendlyResult = JSON.parse(json); | |
| if (mobileFriendlyResult.mobileFriendliness != 'MOBILE_FRIENDLY') { | |
| sendEmail('Mobile friendly test failed for ' + urlToMonitor + ', check https://search.google.com/search-console/mobile-friendly for details'); | |
| } | |
| } catch (e) { | |
| sendEmail('mobileFriendlyMonitor failed for: ' + urlToMonitor + ' with error: ' + e.message); | |
| } | |
| } | |
| function sendEmail(msg) { | |
| MailApp.sendEmail(alertEmail, 'Mobile Friendly Monitor Alert on ' + Utilities.formatDate(new Date(), "GMT", "yyyy-MM-dd'T'HH:mm:ss'Z'"), msg); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment