Google Analytics for Kirby. Set it and forget it. Only Google Analytics ID required as a setting.
<?php echo ga(); ?>
- Load script only for not logged in users.
- Load script only if not on a localhost enviroment.
- Possible to disable the script completely.
- Possible to debug and always load the script.
- Possible to change the script template/snippet path.
- Possible to change the IP blacklist.
ga folder in
- Set Google Analytics id to your
config.php. See options.
<?php echo ga(); ?> in your footer snippet.
The Google Analytics ID is required for the script to work.
You can deactivate the script by setting this value to
The script is only active for not logged in users that are not on a localhost environment. If you always want to have the code active, set this value to
If you don’t like the script and want to change it, change the template path. You have access to
$site in the template.
c::set('plugin.ga.template', __DIR__ . DS . 'template.php');
$ua is the Google Analytics ID.
As default the localhost IP addresses are in the blacklist. That mean that the script will not run on these IP:s except if debug is turned on.
c::get('plugin.ga.blacklist', [ '127.0.0.1', '::1' ] );
I got inspired with the way KirbyAnalytics handle localhost enviroment.
Looks a lot like https://github.com/iksi/KirbyAnalytics
Good to have the debug option though
Yes, I got inspired. The main reason I built my own was that I never want to have the Google Analytics script executed when I’m logged in.
Then I added some extra options, because adding options is so simple in Kirby and it does not make the code much longer.
Looks very cool !, i will test it !
Version 0.2 released
- A snippet is used instead of a function in the footer.
- Removed option
- Added option
<-- 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
can you add a setting for
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
The default snippet looks like this:
<?php if(ga::allowed()) : ?>
ga('create', '<?php echo c::get('plugin.ga.id'); ?>', 'auto');
<?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.
@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!
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.
<?php echo snippet('ga'); ?> what we are supposed to include in the
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.
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>
ga('create', '', 'auto');
<-- 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
` <?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'); ?>