Giter VIP home page Giter VIP logo

gatsby-plugin's People

Contributors

adriaandotcom avatar dependabot[bot] avatar fmcorz avatar jivings avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

squarecat fmcorz

gatsby-plugin's Issues

sa_event not available in window

Hi!

I configured the plugin as on documentation, but I am not able to get the sa_event from the window, the auto events works fine.

In gatsby-config.js:

    {
      resolve: "gatsby-plugin-simple-analytics",
      options: {
        trackPageViews: true,
        events: true,
        eventsGlobal: 'sa_event',
      },
    },

I am using "gatsby": "4.15.2".

Tracking event function implementation:

export const trackEvent = (type: EventType, metadata?: Object) => {
    if (window && window.sa_event && metadata != null) {
        return window.sa_event(type, metadata);
    } else if (window && window.sa_event) {
        return window.sa_event(type);
    }

    return null;
  };

What am I doing wrong?

Minify script in production builds

Would it be possible to minify the script in production environments? I think the script just needs to be injected in another way so gatsby can handle the script itself.

<script id="simple-analytics-loader" type="text/javascript" data-loaded="false">!(function(s, i, m, p, l, e) {
    const parent = document.querySelector('#simple-analytics-loader');
    if (!parent) return;
    const dnt = s.doNotTrack || m.doNotTrack || m.msDoNotTrack;
    if (/yes|1/.test(dnt) && parent) {
      parent.setAttribute('data-enabled', false);
      return console.warn('Simple Analytics: Not loading script when doNotTrack is enabled');
    }
    l = i.createElement(p);
    l.addEventListener('load', function() {
      if (parent) {
      parent.setAttribute('data-loaded', true);
        let event;
        if (typeof Event === 'function') {
          event = new Event('script-loaded');
        } else {
          event = document.createEvent('Event');
          event.initEvent('script-loaded', true, true);
        }
        parent.dispatchEvent(event);
      }
    }, false)
    l.async = "true";
    l.src="https://scripts.simpleanalyticscdn.com/latest.js";
    l.type="text/javascript";
    l.setAttribute('id', 'simple-analytics');
    
    e = i.getElementsByTagName(p)[0];
    e.parentNode.insertBefore(l, e);
  })(
    window,
    document,
    navigator,
    'script'
  )</script></html>

Events support

I can't get the sa_event function to work. Any ideas?

{
    resolve: 'gatsby-plugin-simple-analytics',
    options: {
        // Optional custom domain
        domain: 'sa.mydomain.com',
        eventsGlobal: 'sa',
        events: true,
        trackPageViews: true
    }
}
const windowGlobal = typeof window !== 'undefined' && window
function () {
    windowGlobal.sa_event("click_button")
}

Error: windowGlobal.sa_event is not a function

Needs to support `hostname`.

Hey!

I'm going back and adding analytics to some of my older courses which of course need hostname since they're all on GitHub Pages.

Thanks!
-- Brian

How to setup a custom domain

After setting up the custom subdomain I can't figure out how to add this subdomain to the plugin's options in the gatsby config. Here is your plugin's doc:

If you want to set a custom domain, use this config:

 plugins: [    
   {
     resolve: 'gatsby-plugin-simple-analytics',
     options: {
       eventsGlobal: 'sa',
       events: true,
       trackPageViews: true,
       ignorePages: ['pathname']
     }
   }
 ]

And here is my current config for the plugin (which works without subdomain):

{
      resolve: "gatsby-plugin-simple-analytics",
      options: {
        trackPageViews: true,
        events: true,
        eventsGlobal: "sa_event",
      },
    },

How can I update it to reflect the new subdomain?

Script not detected

I've set up a Gatsby site and I'm using gatsby-plugin-simple-analytics. If you go to https://help.workoutscheduler.de/, you can see that the integration code is indeed installed (check the source code and search for /hello.js).

Unfortunately, Simple Analytics doesn't seem to detect that the tracking code is installed (as shown in screenshot below).

Bildschirmfoto 2019-12-31 um 14 19 24

One possible reason I can think of is that the tracking code gets installed in the head area, while the site may check the body only.


Something else which might be relevant: I've set up Simple Analytics tracking for workoutscheduler.de as a different "website". Will the events from "help.workoutscheduler.de" be tracked there as well? Could this be the reason the script on "help.workoutscheduler.de" is not detected?

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.