Jump to content

Google Analytics


ROLAND_JUNO
 Share

Recommended Posts

@ROLAND_JUNO ... Add the code between <! - Google Analytics -> {GOOGLE ANALYTICS CODE} <! - End Google Analytics -> As below and in place UA-XXXXX-Y enter code ( tracking ID ) ...
This is an example in _main.php from processwire 3.x ...
More info:

<?php namespace ProcessWire;
// _main.php template file, called after a page’s template file	
$home = pages()->get('/'); // homepage
$siteTitle = 'Regular';	
$siteTagline = $home->summary; 
?><!DOCTYPE html>
<html lang="en">
<head id='html-head'>
<!-- Google Analytics -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-XXXXX-Y', 'auto');
ga('send', 'pageview');
</script>
<!-- End Google Analytics -->

<!-- THERE ARE EXAMPLES OF PROCESSWIRE 3.X DO NOT COPY THEM -->
	<meta http-equiv="content-type" content="text/html; charset=utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title id='html-title'><?=page()->title?></title>
	<meta name="description" content="<?=page()->summary?>">
	<link rel="stylesheet" href="<?=urls()->templates?>styles/main.css">
</head>

 

  • Like 2
Link to comment
Share on other sites

@ROLAND_JUNO mine is like this. Using the new gtag. Just paste it in as the first item in the <head> section for your site like so:

<?php namespace ProcessWire; ?>

<!DOCTYPE html>
<html lang='en'>
<head>
  <!-- Global site tag (gtag.js) - Google Analytics -->
  <script async src="https://www.googletagmanager.com/gtag/js?id=UA-NUMBER"></script>
  <script>
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag('js', new Date());

    gtag('config', 'UA-NUMBER');
  </script>
  
  <!-- then the rest of your meta tage/page title/whatever -->
  <meta http-equiv='content-type' content='text/html; charset=utf-8' />
  <meta name='viewport' content='width=device-width, initial-scale=1' />
</head>

You find your specific code (and UA-NUMBER) on the google analytics website.

  • Like 2
Link to comment
Share on other sites

I hope you have been able to get this working.  I will detail how I'm use Google Tag Manager for an upcoming project, just in case you still are having problems.

Background

I'm working on a new website where we are using an Ecommerce Widget.  We normally use Piwik for basic analytics, however this Online Store solution uses Google Analytics to track things (shopping cart, etc).  This is where Google Tag Manager becomes a great solution.  We ended up using both Piwik and Google Analytics.

In Google Tag Manager you create the needed Tags with Firing Triggers.  In this situation, we created one for Google Analytics (using Universal Analytics tag) and one for Piwik (using a Custom HTML Tag).  The Custom Tag is simple, you enter the Piwik code and save.

gtm0.thumb.png.2492c453e8b89b8751f5497d3066c9ed.png

Now that these tags are created, you take the Google Tag Manager code and add it to your website.

gtm1.png.87a94bb6e0ab2a3836d50750b6395ae8.png

Just follow the instructions, as listed.  My website configuration has a _head.inc and _main.inc.

gtm2.thumb.png.805abe57cff7818d2b07775890bfd644.png

gtm3.thumb.png.c1a01824cced305bc27a70cc928ce814.png

You can see (above in the 2 files) where the Google Tag Manager code is put.  It turns out to be a very clean solution when you need to track many things or have more than one analytical tool that needs to track things. 

gtm4.thumb.png.fdf15676c12d1e41a83915f7a0be706e.png

One of the good things about using Google Tag Manager is that you can verify that the 2 Tags are firing, as you need them to.  Additionally, you can create more Tags to track a multitude of things on your website.

Google provides free training courses on Google Tag Manager, if you are interested:

https://analytics.google.com/analytics/academy/

I hope this helps someone out.

 

 

Edited by cstevensjr
Added link for Google Tag Manager Training
  • Like 7
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...