Embed Google Analytics in WordPress [2021]

Marc Wag­ner

June 29, 2021

5 min read|

Goog­le Ana­ly­tics coll­ects infor­ma­ti­on from your visi­tors. This data can help you impro­ve the user expe­ri­ence. In addi­ti­on to visit num­bers, length of stay and page views, you can also query demo­gra­phic data of your visi­tors.

Don’t feel like rea­ding? Then just watch our video tuto­ri­al:

You are curr­ent­ly vie­w­ing a pla­ce­hol­der con­tent from You­Tube. To access the actu­al con­tent, click the but­ton below. Plea­se note that doing so will share data with third-par­­ty pro­vi­ders.

More Infor­ma­ti­on

Google Analytics mit Cookie Opt-in #

With the intro­duc­tion of the GDPR in May 2018, the gui­de­lines for coo­kies were also rede­fi­ned. When coo­kies are set, the visi­tor must first be asked whe­ther they want to allow this. For this reason, Goog­le Ana­ly­tics may no lon­ger be inte­gra­ted direct­ly into the page.

The reme­dy is the Word­Press pre­mi­um plug­in Borlabs Coo­kie.

image 62
Word­Press Coo­kie Dou­­b­le-Opt-in using Borlabs Coo­kie
image 63
Detail view of Borlabs Coo­kies popup

Install the plug­in to start inte­gra­ting Goog­le Ana­ly­tics into Word­Press. After the instal­la­ti­on, go direct­ly to Borlab’s Coo­kies and enter your licen­se first. After that, all set­tings opti­ons are available to you.

image 61
Embed Word­Press Goog­le Ana­ly­tics with Borlabs Coo­kies

To inte­gra­te Goog­le Ana­ly­tics, you now have to switch to the Coo­kies tab. Then scroll down to the Mar­ke­ting item and click on the Add new but­ton.

image 65
Borlabs Coo­kie Mar­ke­ting Add Coo­kie Opt-in

After that, you just need to choo­se the appro­pria­te ser­vice. This is alre­a­dy sup­pli­ed by Borlabs Coo­kies as a tem­p­la­te.

image 66
Embed Goog­le Ana­ly­tics on Word­Press with Borlabs Coo­kies

The tem­p­la­te alre­a­dy con­ta­ins all infor­ma­ti­on about the pro­vi­der, the coo­kies and the run­time. All you have to do now is enter your track­ing ID in the addi­tio­nal set­tings.

image 67
Goog­le Ana­ly­tics track­ing ID stored in Borlabs coo­kie

After­wards you save the who­le thing and the inte­gra­ti­on is alre­a­dy finis­hed.

Now you just need to chan­ge the sta­tus of Borlab’s coo­kie to show the pop-up. You can find the opti­on for this in the Set­tings tab.

It is advan­ta­ge­ous that Borlabs Coo­kie is alre­a­dy deli­ver­ed with stan­dard texts. Fur­ther adjus­t­ments are the­r­e­fo­re optio­nal for the time being.

image 64
Borlabs Coo­kie — Cus­to­mi­ze sta­tus to enable the pop-up.

As soon as you reopen your page, the pop-up will appear. The Goog­le Ana­ly­tics script we added abo­ve will be loa­ded only after con­fir­ma­ti­on.

Disable old Google Analytics integrations #

After you have inte­gra­ted Goog­le Ana­ly­tics with Borlabs Coo­kie into Word­Press, you should defi­ni­te­ly remem­ber to remo­ve old inte­gra­ti­ons.

The best way to do this is to first check the Word­Press Plug­in Mana­ger to see if you have instal­led ano­ther plug­in for sta­tis­tics, such as Goog­le Ana­ly­tics. Nor­mal­ly it is enough to deac­ti­va­te the plug­in to remo­ve the script.

In some cases, the script may also have been inte­gra­ted direct­ly into your the­me. The­r­e­fo­re, you should check your the­me opti­ons as well.

Ano­ther method was to inte­gra­te the script direct­ly into the Word­Press hea­der. The­r­e­fo­re, you should also check whe­ther Goog­le Ana­ly­tics was pos­si­bly depo­si­ted the­re.

Check if Google Analytics was loaded without opt-in #

Thanks to Goog­le Chrome’s deve­lo­p­ment con­so­le, you can find out in no time if Goog­le Ana­ly­tics is loa­ding wit­hout con­sent.

Don’t feel like rea­ding? Then take a look at our video tuto­ri­al:

You are curr­ent­ly vie­w­ing a pla­ce­hol­der con­tent from You­Tube. To access the actu­al con­tent, click the but­ton below. Plea­se note that doing so will share data with third-par­­ty pro­vi­ders.

More Infor­ma­ti­on

The best way to do this is to switch to Chrome’s inco­gni­to mode. You can open this mode with the key com­bi­na­ti­on Ctrl+Shift+N.

After that, sim­ply open your web­site. If you did ever­y­thing cor­rect­ly, you should now see the coo­kie opt-in pop-up from Borlabs.

image 68
Borlabs Coo­kie Opt-in for Goog­le Ana­ly­tics

Igno­re the pop-up and open the deve­lo­p­ment con­so­le of your brow­ser with the F12 key.

Then switch to the Appli­ca­ti­on tab.

On the left side, you will find an ent­ry named Coo­kies under Sto­rage. Expand this ent­ry by cli­cking on the arrow. The­re you should see the domain of your web­site. Click on it.

On the right side, you will now find a list of all coo­kies set by your web­site.

Ide­al­ly, this list is emp­ty.

image 69
Goog­le Chro­me Deve­lo­per Con­so­le for Coo­kies

Howe­ver, if you see ent­ries like the­se, some plug­in, the­me or manu­al­ly added code is unin­ten­tio­nal­ly loa­ding Goog­le Ana­ly­tics. The­r­e­fo­re, you should start sear­ching to find out which script is respon­si­ble for this.

image 70
Goog­le Ana­ly­tics coo­kies in the Chro­me deve­lo­per con­so­le

Google Analytics and privacy #

Sin­ce the intro­duc­tion of the GDPR, some pre­cau­ti­ons have to be taken to be able to use Goog­le Ana­ly­tics on your site:

  1. Con­clude order pro­ces­sing agree­ment with Goog­le:
    You can do this quick­ly and easi­ly via your Goog­le Ana­ly­tics account. You can find ins­truc­tions in the Goog­le Ana­ly­tics Help.
  2. Anony­mi­ze IP:
    Next, you should enable IP address anony­miza­ti­on. To do this, you just need to add the fol­lo­wing to the script:
    gtag(“config”, “%%track­ing­Id%%”, { “anonymize_ip”: true });
    If you are using Borlab’s coo­kie, this line should alre­a­dy be the­re. To be on the safe side, you should still check it.
  3. Do not use “User ID func­tion”:
    Unfort­u­na­te­ly, this fea­ture is not pri­va­cy com­pli­ant. You should the­r­e­fo­re not use it.
  4. Opt-out Coo­kie inte­grie­ren:
    In addi­ti­on to the opt-in, you must of cour­se also offer your visi­tors to manu­al­ly deac­ti­va­te the coll­ec­tion of data. You can read how this works in Google’s user opt-out artic­le.

  5. Limit reten­ti­on of user and event data:
    Goog­le Ana­ly­tics offers you the pos­si­bi­li­ty to deter­mi­ne the dura­ti­on of the data sto­rage yours­elf. You can find this in your set­tings under Track­ing infor­ma­ti­on / Data reten­ti­on. The sto­rage peri­od should not be lon­ger than 12–14 months. Also disable the Reset on new acti­vi­ty opti­on.

  6. Cus­to­mi­ze pri­va­cy poli­cy:
    Don’t for­get to also ful­ly inform your visi­tors in the pri­va­cy poli­cy if and how you use Goog­le Ana­ly­tics. Here you should also refer to the opt-out.
88e86fcb816eff22bc917094df2862d8dd5c0e978b333e6dd5f36f808990c261 96

Arti­kel von:

Marc Wag­ner

Hi Marc here. I’m the foun­der of Forge12 Inter­ac­ti­ve and have been pas­sio­na­te about buil­ding web­sites, online stores, appli­ca­ti­ons and SaaS solu­ti­ons for busi­nesses for over 20 years. Befo­re foun­ding the com­pa­ny, I alre­a­dy work­ed in publicly lis­ted com­pa­nies and acqui­red all kinds of know­ledge. Now I want to pass this know­ledge on to my cus­to­mers.

Hast du eine Fra­ge? Hin­ter­lass bit­te einen Kom­men­tar