Kirby GA (Google Analytics) - Version 0.2

Looks very cool !, i will test it :smiley: !

1 Like

Version 0.2 released

  • A snippet is used instead of a function in the footer.
  • Removed option plugin.ga.template.
  • Added option plugin.ga.snippet.
  • Adds <-- Kirby GA --> if script does not run (on localhost for example).

The main reason for this plugin is to try to never run Google Analytics when you build your site. The script will therefor not run for logged in users and users on localhost. There is an IP blacklist as well.

The repo name has changed

2 Likes

can you add a setting for anonymizeIp?

There are tons of things that can be added to the script and I can’t cover them all. Therefor I made it as a snippet with the latest version of the plugin.

You can override the snippet by simply create your own snippet in your snippets folder called ga. If you don’t like the snippet name you can change it in the config.php:

c::set('plugin.ga.snippet', 'ga');

The default snippet looks like this:

<?php if(ga::allowed()) : ?>
<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', '<?php echo c::get('plugin.ga.id'); ?>', 'auto');
  ga('send', 'pageview');
</script>
<?php else : ?>
<!-- Kirby GA -->
<?php endif; ?>

Is there a way to get some kind of dashboard stats like this :

with this plugin or any other workaround? Thank you in Advance

@gearsdigital is planning a GA dashboard widget, but I have no idea re. the current status of this.

1 Like

@novacanye What you’re looking for is a bit beyond my current target. I’m about to create a basic GA integration with only some dashboard widgets. An extended widget generator is not impossible but a lot of work… Let me think about it.

I’m planning a to provide a beta release in early May.

The installation instruction in the first post aren’t very clear and don’t match the instruction on GitHub.

What does that mean exactly? What ‘ga’ folder? Where do you get that ‘ga’ folder?

As you mentioned further down with your 0.2 release post, this code is now outdated, but anyone using Google or just searching the forum will more likely just read the first post.

The installation instructions in the GitHub repo are much clearer, but one also has to find them first.

Thanks for the plugin! :slight_smile:

For this and other plugins, I recommend to follow the original source, which for most plugins is a Github repository. This forum is a great way to promote and discuss plugins, but it’s not the original source.

Keeping the documentation updated in the forum means keeping two places up to date, the forum and the repository. Also, because the post is no longer editable after a specific time, I can’t keep it up to date without PM one of the crew members each time.

But because you had this problem, I’ve learned that we should probably never write installation instructions or details about the plugin in the forum, only more general features, images, videos but not exactly how to use them, because it might change over time.

In conclusion: Always go to the original source.

Hello! I am having trouble receiving any hits on the Google Analytics dashboard after I followed your Github tutorial.
Is <?php echo snippet('ga'); ?> what we are supposed to include in the footer snippet?

Thank you!

Yes, you have to include that snippet in the footer, no need to echo a snippet,though (although it says so in the plugin docs)

<?php snippet('ga'); ?>

But if you are on localhost, not logged in or haven’t added your GA id in the config, it won’t work.

1 Like

Hi, thanks for the help!
I am not on localhost, and I have added the GA id.

However I am a bit confused with the “logged in” part.
On the Github repo it says: Doesn't run the GA script if you are logged in.
In your response above you suggest I should be logged in, if I understand correctly.
Can you clarify?

Many thanks again!

Oh, sorry, the other way round, yes! Anyway, if you have added the snippet in the footer, what do you get on the page in dev tools?

Got it, thanks for the clarification.
There is no www.google-analytics.com folder in the dev tools Sources…which can’t be good I guess!

What I meant is if you see these two script tag in the footer in dev tools:

<script async="" src="https://www.google-analytics.com/analytics.js"></script>
<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', '', 'auto');
  ga('send', 'pageview');
</script>

Or <-- Kirby GA --> if script does not run.

No, I don’t. I’m pretty sure I’m not loading the pluggin correctly.
This is my footer.php file:

` <?php echo js("assets/js/jquery.min.js") ?>
<?php echo js("assets/js/underscore.js") ?>
<?php echo js("assets/js/main.js") ?>
<?php echo js("assets/js/jquery-ui/jquery-ui.js") ?>
<?php echo js("assets/js/classie.js") ?>
<?php echo js("assets/js/screensaver.js") ?>
<?php echo js("assets/js/isotope.js") ?>
<?php echo js("assets/js/modernizr.custom.js") ?>
<?php echo js("assets/js/jquery-zoom/jquery.zoom.js") ?>
<?= js('assets/plugins/embed/js/embed.js') ?>

<?php foreach($page->files()->filterBy('extension', 'js') as $js): ?>
<?php echo js($js->url()) ?>

<?php endforeach ?>
<?php echo snippet('ga'); ?>
`

Well, you should at least see the comment @jenstornell posted, otherwise maybe the plugin is not installed correctly, maybe?

What is the folder name of the plugin in /site/plugins?

Yep. I realized that I had the name of the plugin folder wrong (I think):
The folder name should be kirby-ga rather than ga - is this right?

That is correct, the folder name must be the same as the (main) php file in the folder (kirby-ga), otherwise the plugin is not loaded.