Skip Navigation

[Resolved] Google Analytics with two domain + Divi integration + Toolset Layout

This support ticket is created 7 years, 4 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+01:00)

This topic contains 6 replies, has 2 voices.

Last updated by oriolc 7 years, 4 months ago.

Assisted by: Nigel.

Author
Posts
#518314

I have a website (www.encuentramiretiro.com) which have different domains for languages (in english is hidden link).
I created with Divi theme and Toolset Layout, Creed, Types... and I use sometimes pages created with Divi theme and sometimes pages created with Layouts (Header+Footer+Child)
I inserted my google analytics script in Divi Child header for the two domains language.
In pages created with Divi, google analytics works.
But in pages created with Layouts won't appears google analytics.
Where can I add google script (uses php to choose language) to follow this Layout pages with Google Analytics?

#518363

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Hi Oriol

For pages where you have a Layout assigned then your theme's PHP templates are bypassed when rendering the page, Layouts handles rendering the entire page.

So changes you make in your theme's header.php will be ignored.

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.

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

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/

There are lots you can choose from, I wouldn't expect them to be affected by Layouts, but if you find one doesn't work, try another one.

If you can't find one that works then let me know and I'll investigate further.

#518389

Ok. Thanks for the solution, but I have some problems with that solution

As I described, I use php to determinate the domain language script.

Example: <?php if(ICL_LANGUAGE_CODE=='es'){?><script></script><?php } elseif(ICL_LANGUAGE_CODE=='en'){?><script></script><?php } ?> and each script is for a different language.

From WPML is the only solution they gave me.

And with pluggins I can't insert different scripts for different domain.

A part, that pluggins are very weight. And, right now, my website have two much pluggins (Woocommerce, Types and WPML) to add a new pluggin.

With Toolset based theme there is a heder layout file. Isn't there a similar way to insert that script with php????

#518424

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Hi Oriol

I'm going to need to do some testing to establish the best way to do this because you are using Layouts with the Divi integration plugin.

I'm not going to be able to complete that until after the weekend now, I'm afraid, but I'll get to it as quickly as I can.

#519387

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Hi Oriol

When using the Divi Integration plugin, the header.php file which is used on pages where a Layout is assigned is provided by the plugin at plugins/layouts-divi/application/theme/view/header.php

One solution is for you to edit that file and insert the same code there that you have in your child theme's header.php.

The problem, of course, is that you will lose the code you add if you update the integration plugin (which, at least, happens infrequently).

I'm trying to see where the use of that template file is set but I haven't pinned it down yet, and I will keep looking and get back to you with, hopefully, a better solution.

#519715

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Hi Oriol

I went over this again, and I think the best solution which avoids losing your changes if and when the Divi integration plugin is updated is to change how you add the required code to your theme's header.php.

Instead of adding the code directly to the header.php of your theme, use an action hook present in header.php (both in your child theme's version and the version which ships with the Divi Integration plugin) to add the code.

So remove the code from your child theme's header, and add the following to your functions.php file:

/**
 * Add code snippet to Divi header
 */
add_action( 'et_head_meta', 'header_snippet' );
function header_snippet(){

	// add your code here

}

Can you try that and let me know how you get on?

#522586

Yes,
With this last code added to functions I can see analytics in Divi and Layouts header.
And I will have no problems updating layouts.
Thanks a lot.

This ticket is now closed. If you're a Toolset client and need related help, please open a new support ticket.