I recently noticed that an event tracking of Google Website Translator is no longer available.
What I was changed is the code of Google Analytics: old ga.js code to new Universal Analytics code, analytics.js.
It seems Google Translate code is not updated for Universal Analytics. Here is my attempt to fix it by modifying core codes of Google Translate.
Put Google Website Translator in your blog
You can easily put Google Website Translator by following the instruction on the page.
You can also put your Analytics code to track translation events by Google Analytics.
Events have information of which languages are used in Event Label.
I found some posts related to this problem:
The first one was posted in September/2013, and the latter was posted on 22/January /2015. So, it seems this problem is a remaining problem since Universal Analytics was released.
How to fix
From Google Website Translator, codes like below are provided:
1 2 3 4 5
Then, let’s check element.js:
It calls main.js:
If your browser’s setting is other than English, a direct access to element.js shows different codes comparing to the Beautified code.
For example, with Japanese environment, element.js calls main_ja.js instead of main.js
In the below, element_main.js is common for all language, while such 0/main.js is replaced by 0/main_ja.js in Japanese environment.
It is too tight to follow all scripts. Therefore, in this attempt, I use only main.js from element.js. As a result, the translator button will be always English version.
Anyway, main.js calls:
Let’s check these scripts precisely. Hereafter, I would use 0_main.js for above element/0/main.js to distinguish from element/man.js.
In the beautified code, you can find following part in 0_main.js:
1 2 3
So, it uses only functions of
_trackEvent of ga.js.
As a result, we can not make an event with Universal Analytics.
Ok, now the place at where the event is created becomes clear. Then, it should work if the event track function of Universal Analytics is added by following my previous post: Notice a copy event on your blog in Google Analytics, like:
1 2 3 4 5 6 7 8 9 10 11 12
1 2 3 4 5 6 7 8 9 10 11 12
Window object in 0_main.js and element_main.js, respectively.
Window should have
ga if analytics.js is used on the page (in the normal way),
_gaq of ga.js.
a.e have values of the language, so it should be in the 5th argument (Event Label).
Google Website Translator and
So in both files,
ga works in the same way.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
1 2 3 4 5 6 7 8 9 10
In the last, update the original Google Website Translator code in
1 2 3 4 5 6 7
to call the local scripts.
(In the modified element.js,
googleTranslateElementInit is already set. (if you started from above beautified code.))
Now I can see translation events.
It may be better if I can fix with short codes from outside, but it seems difficult to do so, then got all scripts and modified locally.
This problem was posted in Google Group of Analytics, so I think Google engineers will notice and fix it soon.
Until then, I will keep this fix to track translation events.