SQL Google Analytics Search Console Code Addition

Adding Google Analytics and Search Console Code Using SQL

We'll add JavaScript code for Google Analytics and Google Search Console. We'll add it using SQL commands via MySQL.

Shou Arisaka
4 min read
Oct 30, 2025

To add JavaScript code for Google Analytics and Google Search Console to the Keni theme, it's impossible to edit and add it to index.php or header.php, so

The normal way would be to open Keni Settings (Site-wide Common) > Code insertion field directly before </head>

from the WordPress admin panel and paste it there.

However, this method is very tedious. You have to access the site, log in, open Keni settings... and repeat this for each site. A bit troublesome.

So, let's add it using SQL commands via MySQL.

Environment

MySQL client: Workbench Server: xserver

The method to access xserver's MySQL from Workbench is explained in a separate article.

About Keni Tables

There are tables called wp_keni_pv and wp_keni_setting706, but Keni settings are stored in wp_keni_setting706. wp_keni_pv is not used much. For cases like "I haven't done any access analysis but want to see past access history!" if you happen to be using Keni, you can select from here to quickly view access numbers or create statistics. That's about the only demand for it.

select * from wp_keni_pv ;
#=> View count for each post is stored.

Main SQL

{/* ``` select * from wp_keni_setting706 ; #=> Output the entire table.

select ks_val from wp_keni_setting706 where ks_id=12 ; #=> Output the field value corresponding to “code insertion field directly before head”.

update wp_keni_setting706 set ks_val = CONCAT_WS(‘\n’, ks_val, ‘This string will be appended’) where ks_id=12 ; #=> Append string with line break. CONCAT_WS()

select * from wp_keni_setting706 ; #=> Output the entire table.

select ks_val from wp_keni_setting706 where ks_id=12 ; #=> Output the field value corresponding to “code insertion field directly before head”.

update wp_keni_setting706 set ks_val = CONCAT_WS(‘\n’, ks_val, ‘This string will be appended’) where ks_id=12 ; #=> Append string with line break. CONCAT_WS()


## How to Do It

<p>Now, let's actually update the field value with SQL.</p>

<p>First, Search Console.
If Search Console code data is already in there, skip this.</p>

<p>To check if it's stored, you can execute <code>select ks_val from wp_keni_setting706 where ks_id=12 ;</code>, right-click on the displayed field, and click <code>open value in viewer</code> to view all the text in the field.</p>

Update Search Console code.

update wp_keni_setting706 set ks_val = ’ ’ where ks_id=12 ;


## Escaping Single Quotes in Analytics Code

<p>Next, we want to update by appending Analytics code (we could update it together with Search Console code, but this time we're assuming the common situation where "Search Console code is already stored").</p>

<p>Actually, Analytics code contains both <code>"</code> and <code>'</code>, meaning both single quotes and double quotes are mixed in.
So, normally if there were only single quotes, you'd wrap the value in double quotes, and if there were only double quotes, you'd wrap it in single quotes.
However, because it's like this, you need to escape one of them.
For the escape process, you could manually "add &#92; before '" but I don't like that, so I wrote a script.</p>

sed -e “s/’/\‘/g” << EOT ’ EOT

#=> ’


<p>As you can see, it replaces it.</p>

<p>Let's do this to the Analytics code.
(This is a WSL environment, so if you're not in a WSL environment, please decide about clip.exe yourself.)</p>

sed -e “s/’/\‘/g” << EOT | clip.exe

EOT


<p>And here's the copied data. ('&#92;' is a common escape character, and that's the same in HTML and Markdown, so the &#92; has probably disappeared, but please understand.)</p>

<p>Now let's update this in MySQL.</p>

update wp_keni_setting706 set ks_val = CONCAT_WS(‘\n’, ks_val, ’

’) where ks_id=12 ;


<p>Then, check it with <code>select ks_val from wp_keni_setting706 where ks_id=12 ;</code>.</p>

<p>...It's properly in there. The append also worked well.</p>

## Another Way to Add Code

<p>This time we used such a complicated method, but with Workbench, you can not only view field values directly but also edit them, so
in other words,</p>

use YOUR_DATABASE_NAME ; select ks_val from wp_keni_setting706 where ks_id=12 ;


<p>You can execute this SQL, right-click on the displayed field, open the editing screen with <code>open value in viewer</code>, edit it, and update it with <code>apply</code>.</p>

<p>This way is simpler.</p>

<p>However, Keni's table says read only, so it seems you can't edit it this way...</p>

Share this article

Shou Arisaka Oct 30, 2025

🔗 Copy Links