GithubHelp home page GithubHelp logo

Comments (10)

sifigi4335 avatar sifigi4335 commented on September 1, 2024 2

It is working now! Thanks a lot. Let me leave it running for a few days and see.

from minimal-analytics.

marshmallowcreme avatar marshmallowcreme commented on September 1, 2024 1

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.

marshmallowcreme avatar marshmallowcreme commented on September 1, 2024 1

@jahilldev Thank you. I will do that if and when I decide to add a JS build tool.

from minimal-analytics.

jahilldev avatar jahilldev commented on September 1, 2024

@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.

sifigi4335 avatar sifigi4335 commented on September 1, 2024

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.

jahilldev avatar jahilldev commented on September 1, 2024

Hey @carerragt,

Great, glad it's working out well 👍

from minimal-analytics.

jahilldev avatar jahilldev commented on September 1, 2024

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.

fablau avatar fablau commented on September 1, 2024

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.

jahilldev avatar jahilldev commented on September 1, 2024

@fablau I've replied in your new issue, please continue on in there 👍
#38

from minimal-analytics.

fablau avatar fablau commented on September 1, 2024

Thank you James! I'll be seeing you there...

from minimal-analytics.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.