Skip Navigation

[Resolved] How to insert Google analytics into layouts

This support ticket is created 7 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 7 replies, has 2 voices.

Last updated by Minesh 7 years, 2 months ago.

Assisted by: Minesh.

Author
Posts
#567322

Max

I am trying to: insert Google analytics into Layouts.
I know that Layouts remove the <script> code, but i need it.
I tried to add this code to the content template, but it was also deleted.
What will be your advice?

#567437

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

You can add the Javascript (as described in the Google documentation: hidden link) in the custom JS section for Layouts at Toolset > Layouts CSS & JS.
[ Please note that you need to add your google analytics JS WITHOUT <stript> Tag - <stript> tag will be automatically appended]

However, this won't add the code in the head of your page as is recommended.

But - I suggest you use a 3rd party plugin to add the Google Analytics code, such as:
=> https://wordpress.org/plugins/google-analytics-dashboard-for-wp/
=> https://wordpress.org/plugins/google-analytics-for-wordpress/
=> https://wordpress.org/plugins/googleanalytics/

#567564

Max

Minesh,
I registered a shortcode and put the code in there, as Luo advised a similar forum topic.

 
add_shortcode( 'google', 'google_func' );
function google_func() {
    return 'google code here';
}

Then I inserted this shortcode into the footer of Layouts (parent layout)
Is this a bad example? Does such an approach affect speed?

One more thing.
I would like to ask whether it is possible for Layouts to work as Content template, so that I can insert raw HTML and mix it with shortcodes. Sometimes it is too difficult to deal with visual cells and their limitations...

#568338

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - as per the standard we should add Google Analytics code to site's head (header) section. You can see the benefits of doing that with the following link:
=> hidden link

Regarding - the another question as I understand you would like to build the layout using PHP template. You can check the theme we offer "Toolset starter" theme to know how you can build your theme's PHP template with Layouts:
=> https://toolset.com/account/downloads/#toolset-themes

You should download the theme and check the source fiels.

#568369

Max
screencapture-agroonetest-info-msn-wp-admin-admin-php-1505032459629.png

Hello Minesh.
I use a Toolset starter theme in my project. And for the first time I try to work with Layouts. First of all, I want to say that I like the idea of ​​complete freedom and control of the template from top to bottom. But I'm confused by some limitations. For example, the lack of the ability to insert code into the tag script. What can be easily done in a footer.php. Now I'm working on a landing page. And I want to say that it's faster for me to write the HTML code in the editor (sublime + emmet), than to create the design in Layouts. Maybe I'm doing something wrong?
I attach a screenshot of my layout. As you can see, I use a large number of visual cells, sometimes this leads to slow work when editing a layout. Perhaps it's better to use fewer visual cells, for example, each cell is a section that contains HTML and toolser shortcodes.

I just want to understand how I can use Layouts. I read all the documentation, I understand how it works, but I'm afraid that I will not be able to fight with its limitations or conflicts with other plugins (maybe) when the site is ready.

I also noticed that when you use Layouts, the page loads a little longer (1.3 before activating Layouts and 1.6 seconds after activation).

Finally, my main question. What will I lose if I refuse to use the Layouts in my workflow? After all, not so often client have to change the header, footer ..., it does not change often ....
What do you advise?

P.S. I read the news on the blog (generetepress intagration)
https://toolset.com/2017/09/introduction-brand-new-theme-integrations/
so I can change the sidebar, hide the title in single template...etc. Its perfect!

#568382

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - We are working on Layouts and from now on Layouts will only be useful and have effect on your content area (body). Header and footer will not be part of Layouts and we allow that it should be controlled by your theme.

You can find more info on that here:
=> https://toolset.com/documentation/user-guides/layouts-theme-integration/

We are working on new Layouts Docs and it will take some time that's the reason I shared the idea to look at the "Toolset Starter" theme as the example so you will be able to know how this theme is built. Layout might affect the speed as well as it will be overriding the the_content part.

Finally, my main question. What will I lose if I refuse to use the Layouts in my workflow? After all, not so often client have to change the header, footer ..., it does not change often ...
What do you advise?
==> As I said, layouts will not use for header and footer but for your content area. So its up to your requirement that if you would like to go with Layouts or not. As you said you are more comfortable by editing theme's PHP templates you may leave layouts as you are able to build PHP theme templates with HTML on your own.

But if you would like to use layouts different features like different cells and other things then you should go with Layouts.

#568386

Max

Thank you for the clarification.
Layout might affect the speed as well as it will be overriding the the_content part.
Is this the same way that Content Templates work? If so, why Content Templates work a little faster?
Anyway, I think that It will be enough for me two plug-ins for building and displaying the content - Types + Views.

As you said you are more comfortable by editing theme's PHP templates you may leave layouts as you are able to build PHP theme templates with HTML on your own.
Thank you, but my knowledge is limited to httml and css. I'm just starting to learn php...

#568398

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Is this the same way that Content Templates work? If so, why Content Templates work a little faster?
Anyway, I think that It will be enough for me two plug-ins for building and displaying the content - Types + Views.
=> Well - I mean to say it depends on the layout you build. For instance - if you build layout having 10 rows and you are using 25 different cells obviously it will be expensive. I also checked the layout screenshot you shared and I think the load time is expected for that layout as the layout screenshot you shared having around 20 rows and 30 cells.

Thank you, but my knowledge is limited to httml and css. I'm just starting to learn php...
==> Well - I asked you to use PHP tempalte because you confirm that you are enjoying to build PHP template as you find more easy to edit HTML and CSS there. So if that is not your cup of tea then I suggest you should go with GUI.