Breaking News
You are here : Home / Web development / CakePHP / Easy CakePHP Google Analytics Integration
CakePHP easy Google Analytics integration

Easy CakePHP Google Analytics Integration

Easy CakePHP Google Analytics Integration :

hello Guys ! cakePHP Google Analytics integration is very easy to implement.we need to get google analytics code and paste in our page .it is usually a script.the cakePHP framework is highly reusable so in cakePHP we will create a element to integrate google analytics to cakePHP.So lets move on and see the Easy CakePHP Google Analytics Integration tutorial .

[separator /]

Easy CakePHP Google Analytics Integration : Tutorial -

So lets move on our tutorial towards cakePHP Google Analytics integration .which is very very easy.we need to create a element ,and edit cake config then call the created element.Lets see how we do that.

CakePHP Google Analytics Integration : create Google analytics element -

First of all we need to Create  a element in app/views/elements/google-analytics.ctp .and put our google analytics code in it but in cakey manner .lets see how we do it.
app/views/elements/google-analytics.ctp :

Notice carefully that in the above file the google analytics property code is fetched from the cake configuaration .actually we add our google analytics property code to cakePHP config file ,which we do in later step.Lets move on to our next step to integrate cakePHP with google analytics .

CakePHP Google Analytics Integration : Include in the layout -

Now we gonna include the Element file in the our layout which is used all over the app.say we have layout name main.ctp .then inside main.ctp(app/views/layouts/main.ctp) just before closing head tag(</head>) tag we write the line below:

app/views/layouts/main.ctp

Now that we have added the element in our layout the important thing is to define the Tracker code in the Config file .Lets do it then.

CakePHP Google Analytics Integration : Define Tracker Code in Config File -

now we need to define our tracker code in the config file which we read in the element file.So lets define it.Initialize it with you google analytics tracker code.also you can deactivate google analytics by initializing it with false.

app/config/core.php

I was All ,i hope you like this tiny and easy tutorial.Keep visiting for latest updates.

[separator /]

This Post Has Been Viewed 195 Times

Tags : , , ,

2 Replies

  1. giovannydearco says:

    thanks =)

  2. yassine says:

    Hello. thank you for the post. It seems to work but I dont get any analytics in the dashboard even though I have Tracking beacon sent! when debuggin the action.

Leave a Reply

%d bloggers like this: