Thursday, May 1, 2014

New Google Schema implementation for Phone Numbers - little helper for lots of phone numbers

Google is showing phone numbers now for company searches

Nope, not happy about the fact that Google is showing phone numbers for company searches - but not for phone searches. How much sense does that make?

I prefer online, usually, and call only as a last resort. Calls take much longer, sometimes it is hard to hear or understand what the other's say. And sometimes I find it incredibly aggravating to be on a call for hours to fix something that the company I am calling "broke" in the first place - or did not prevent. (Although I know there are many companies involved, in producing one product). And I also know, most companies (including the one I work for)  really try hard to give good online and phone support.

And now Google is showing support phone numbers for companies - no matter if it is an online only company.  And they show them as part of the knowledge graph - but NOT when someone searches for a phone number. How smart is that.

And they are currently  not showing for Chrome books or for google - how fair is that?

The schema documentation works just fine, watch for this:
  • the visible number on the page needs to be the same as the one in the json / schema part
  • for multiple contact points for the same organization, that part of the code can be iterated, comma separated
  • phone numbers for several countries can be integrated on one page. 

Script for many phone numbers:

Ok, so I had to update ~ 80 country phone numbers, and got just one not very good list of phone numbers, including international calling code. First I started concatenating in my beloved MSFT Excel, but that's no fun, especially since quotes need to be escaped (doubled), so I ended up with a lot of double quotes - which I then had to remove in a later step. But this needed to be done quickly, once I had the final list, which made me do this little script.

This script loops through the list of phone numbers with awk, writes the two parameters into variables, and fills the info in the schema snippet. As a result, the script generates one snippet for each country and phone number.

Three files needed, the script (shown at the end) a list of phone numbers and the schema for this kind of phone numbers.

This is the schema info we were going to use, where I used two placeholders - changeNumber and changeArea:
The list of phone numbers looks like this, and is tab delimited:

And now the script:
awk '{print $1, $2}' tab-phone-numbers | while read input2 input1
awk -v var1="${input1}" '{ sub("changearea",var1)} {print $0}' phone-code-snippet |  awk -v var2="${input2}" '{sub("changenumber",var2);print$0}'>> phone-results
What really helped me do this was the trick to use read to get the output into variables (bold). Found this first here (thanks duckeggs01) and confirmed on my trusted source for man pages online - ss64 . I am sure I'll use this more, very quick and easy, efficient.
First part is a loop with awk through the numbers assigning each field value to a variable. Then nested two awk commands - assigning the external variable to an internal. Then, replacing the first variable the first placeholder, piped into a second awk with the second variable replacing the second placeholder, ... done.

In this first run this script produced one complete snippet per country - good if you need the snippets on several pages. For usage on one page, the template for the schema needs to be changed to only include the contact point info, then run, and add header / footer afterwards to the whole section.

No comments:

Post a Comment

Bookmark and Share