Where to Put "Google Tag Manager" Script??

Hi Guys...

So google tag manager cannot go inside PHP. There's a script that will break.

Google says to put it just after the opening <body> tag.

So where should I put it?

Here's the doc:



  • In your custom plugin init function

    elgg_extend_view('page/default', 'myplugin/page/elements/tagmanager', 0);

    Then create the view 'myplugin/page/elements/tagmanager' with that snippet

  • oh. I don't know how to do that?

    There's no page I can just copy and paste into??


  • The usage of elgg_extend_view results in code of the view myplugin/page/elements/tagmanager being added to the view page/default. You could add the code to enable the Google Tag Manager to the file views/default/page/default.php directly. But this approach is discouraged because it will managing your site much more difficult later on (http://learn.elgg.org/en/2.0/guides/dont-modify-core.html).

    Instead of adding the code directly to the original view file you can create a little plugin that deals with this modification (and possibly any other of these kind of modifications you might want to add at a later time). Creating such a plugin is not difficult. The bare minimum of a plugin is a manifest file and a start.php in the main plugin folder (http://learn.elgg.org/en/2.0/guides/plugins.html). You can look into the manifest.xml and start.php files of another plugin to have a starting point.

    The start.php file only needs an init function with the single line of code posted by Matt above. And then you only need to create on additional file within your plugin at the location myplugin/page/elements/tagmanager.php and with this file you only need to add the code you would have added to an existing Elgg core file otherwise.