Coder Social home page Coder Social logo

Instrument with GA about interactive-examples HOT 8 CLOSED

mdn avatar mdn commented on June 18, 2024
Instrument with GA

from interactive-examples.

Comments (8)

stephaniehobson avatar stephaniehobson commented on June 18, 2024 1

Some ideas of what needs to be instrumented:

User interactions:

  • copy/paste
  • when a user makes their first edit
  • CSS: when a new example is selected
  • JS: when 'run' is clicked

Performance:

  • time to samples being interactive (we might get this for free with GA)

from interactive-examples.

stephaniehobson avatar stephaniehobson commented on June 18, 2024 1

Yeah, the Navigation Timing API is perfect for that :)

I thought of something else we need to track: error messages. I think it's possible broken examples won't run at all but if they do it would be nice to be able to watch for them.

What we do in kuma might be a good starting point.

from interactive-examples.

schalkneethling avatar schalkneethling commented on June 18, 2024

After having looked at this some and considering our options, I propose we do the following:

Inisde interactive-examples

We use postMessage as follows

// run button is clicked
mceAnalytics.trackRunClicks();

The above will happen in the events.js file where we will track all events happening on the editor.
https://github.com/mdn/interactive-examples/blob/master/js/editor-libs/events.js

This will then call the code here:
https://github.com/mdn/interactive-examples/blob/master/js/editor-libs/analytics.js#L11

Inside analytics.js on Kuma

// Adding to globally available mdn object
    var analytics = mdn.analytics = {
        /**
         * Handles postMessage events from the interactive editor, passing of
         * the data to `trackEvent` if the origin of the message is what we expect.
         * @param {Object} event - The event Object received from the postMessage
         */
        interactiveExamplesEvent: function(event) {
            if (event.origin !== 'https://mdn.github.io') {
                return false;
            }
            this.trackEvent(event.data);
        },
       ...
};

// add event listener for postMessages from the interactive editor
win.addEventListener('message', analytics.interactiveExamplesEvent, false);

Thoughts? @stephaniehobson @wbamberg

from interactive-examples.

stephaniehobson avatar stephaniehobson commented on June 18, 2024

I like the use of postMessage 👍

The ga object can take a callback. For security reasons I would like kuma to strip the callback out of the data before passing it to trackEvent.

from interactive-examples.

schalkneethling avatar schalkneethling commented on June 18, 2024

For security reasons I would like kuma to strip the callback out of the data before passing it to trackEvent.

Definitely. We would not want to just trust the because the domain matches all is ok.

from interactive-examples.

schalkneethling avatar schalkneethling commented on June 18, 2024

Pull request for the Kuma side: mdn/kuma#4305

from interactive-examples.

atopal avatar atopal commented on June 18, 2024

Hey Schalk, can you confirm that we are tracking all events listed by Stephanie?

from interactive-examples.

schalkneethling avatar schalkneethling commented on June 18, 2024

As we are posting messages to MDN for GA, I reckon we need to calculate the time it took for the iframe to load. It seems the best way to accomplish this would be to use the Navigation Timing API - https://caniuse.com/#feat=nav-timing Thoughts @stephaniehobson @wbamberg

from interactive-examples.

Related Issues (20)

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.