[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.
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?
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.
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????
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.
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
}
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.