Site logo

Archived topic

Google Tag Manager and Elementor

9 replies · Started by Uwe on October 3, 2017

Viewing posts 1–10 of 10

hi guys

Have just inserted GTM code into the two sections in Hooks, being wp_head and Before_header.

Doesn't seem to find the first part of the code.

Maybe I am missing something:

Here are the details for the page:

- Default Template, not Elementor Canvas
- At first, I had "Header" turned off in "Disable Elements" for that page (Homepage), but even not disabling that didn't make a difference, not sure if that had anything to do with it

I have also tried one of you other suggestions and copied header.php into the Child Theme as follows and wonder if this is done correctly.

<?php
/**
* The Header for our theme.
*
* Displays all of the <head> section and everything up till <main id="main">
*
* @package GeneratePress
*/

// No direct access, please
if ( ! defined( 'ABSPATH' ) ) exit;

?><!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-5BPTXW');</script>
<!-- End Google Tag Manager -->
<meta charset="<?php bloginfo( 'charset' ); ?>">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<link rel="profile" href="http://gmpg.org/xfn/11">
<?php wp_head(); ?>
</head>

<body <?php generate_body_schema();?> <?php body_class(); ?>>
"><?php _e( 'Skip to content', 'generatepress' ); ?>
<?php do_action( 'generate_before_header' ); ?>
<?php do_action( 'generate_header' ); ?>
<?php do_action( 'generate_after_header' ); ?>

<?php do_action( 'generate_inside_container' ); ?>

Thanks for your help
Uwe

Hi there,

Which part is not working? Where did the instruction say to insert the code?

Hi Leo

there are several support threads on the forum here, some suggest the Hooks, one the header.php file into Child.

FYI, I have just noticed that the tracking now works. It seemed to take some time to filter through to Google.

Before we close the thread, maybe you can highlight if there is a difference to how this is set up depending on using a Default page template or an Elementor Canvas?

thanks again

You should add that into the wp_head hook in GP Hooks - not into the actual file.

The wp_head hook should be available when using the Canvas page template.

thanks Tom

No problem :)

hi tom.
so what should i do best?
create a header.php file into the child theme and put the google tag manger code?
or put it into the wp_header / body with hooks? (and if so how to do it exactly?)
please help,
thanks

ok thanks.
will try.

No problem :)

This archived topic is closed to new replies.