Comments (10)
It is working now! Thanks a lot. Let me leave it running for a few days and see.
from minimal-analytics.
I'm using Eleventy, which is a static site generator like Hugo, but based on Node. I didn't want to depend on an external CDN (unpkg) and I didn't want to manually copy the script into my app, because I wanted it to stay current. So I used the following code to copy from the node module at build time.
This goes in .eleventy.js
:
module.exports = function (eleventyConfig) {
eleventyConfig.addPassthroughCopy({"./node_modules/@minimal-analytics/ga4/dist/index.js": "js/analytics.js"});
}
You would just change "js/analytics.js"
to the subdirectory and filename you want to use on your site.
Then in the head tag of my template, I used the following tag:
<script src="{{ "/js/analytics.js" | url }}"></script>
Thanks for all your great work, @jahilldev!
from minimal-analytics.
@jahilldev Thank you. I will do that if and when I decide to add a JS build tool.
from minimal-analytics.
@carerragt Hi there,
Thanks for reaching out 👍
Given you're using Hugo to build your site, it's now occurred to me that we don't have an easy way for users like yourself (who are not using a JavaScript based build tool) to include the script on a page. Currently, the instructions assume a Node environment.
I've just pushed a new version that remedies this. In the README
you'll now find two new sections Onload and CDN.
You'll find the built script at the link below:
https://unpkg.com/@minimal-analytics/ga4/dist/index.js
You can either include it on the page as is, or self host it. Once included, you'll need to define two properties on the window, trackingId
and autoTrack
.
A full example is below:
<script src="https://unpkg.com/@minimal-analytics/ga4/dist/index.js" async />
<script>
window.minimalAnalytics = {
trackingId: 'GX-XXXXX', // <-- replace with your GA4 property ID
autoTrack: true,
};
</script>
Let me know how you get on.
Thanks for contributing!
from minimal-analytics.
Hi. It has been working well and I like it! Just getting significant amount of "unassigned" traffic which I think is a limitation of GA4. Thanks again and cheers!
from minimal-analytics.
Hey @carerragt,
Great, glad it's working out well 👍
from minimal-analytics.
Hi there @marshmallowcreme,
Thanks for sharing your implementation! I'm actually using 11ty with this library too, but in a slightly different way. If you're using a JavaScript build tool for your client side code, including the script is as simple as doing this:
https://github.com/jahilldev/jameshill.dev/blob/main/src/modules/shared/shared.entry.ts#L20
import { track } from '@minimal-analytics/ga4';
track('GX-XXXXXX'); // or define on window
Thanks again for sharing, great example 👍
from minimal-analytics.
I am sorry to re-open this issue, but I tried to implement the simplest solution for me, by adding just the following lines to my pages' head:
<script src="https://unpkg.com/@minimal-analytics/ga4/dist/index.js" async />
<script>
window.minimalAnalytics = {
trackingId: 'G-XXXXX', // <-- replace with your GA4 property ID
autoTrack: true,
};
</script>
But I get now hits. Of course, I have replaced the 'G-XXXXX' with my GA4 property ID. Is there anything else I need to add?
from minimal-analytics.
@fablau I've replied in your new issue, please continue on in there 👍
#38
from minimal-analytics.
Thank you James! I'll be seeing you there...
from minimal-analytics.
Related Issues (18)
- Do you update CDN code? HOT 2
- Customize analytics endpoint HOT 6
- Not measuring engagement time HOT 7
- Tracking code HOT 4
- Add a note about what options to toggle in GA4 HOT 11
- Adding to Hugo HOT 4
- Using jsDelivr? HOT 4
- gtag() compatibility HOT 8
- Not tracking downloads through form submit HOT 8
- Minimal Analytics are getting blocked by Ad Blockers + Firefox Private Mode HOT 6
- Unable to make it work with CDN implementation HOT 11
- require.min.js:17 Uncaught Error: Mismatched anonymous define() module: HOT 15
- Unable to override default parameters
- Direct localStorage/ sessionStorage access prevents usage from Worker context or Safari Private tab HOT 8
- Inline onclick event tracking HOT 8
- Beacon parameter inconsistencies from their original GA4 specs
- How to use minimal analytics CDN-script with GA4? without node HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from minimal-analytics.