Giter VIP home page Giter VIP logo

Comments (6)

DavidWells avatar DavidWells commented on June 11, 2024

heartbeat ticks every 3 sec and flushes any queued events

heartBeat(store, getPlugins, instance)

abort should be a function there. I've tested this locally with another identifyStart plugin. Are you calling abort from anywhere else? Maybe verify it exists before calling it with typeof abort === 'function' check

Also, It looks like you are missing required name key from your plugin. It should be:

const validationPlugin = {
  name: 'my-plugin-name',
  identifyStart: ({ payload, abort }) => {
    const prev = identifyTraits[payload.userId];
    const traits = { ...identifyTraits[payload.userId], ...payload.traits };
    if (isEqual(prev, traits)) {
      return abort('Identify traits is the same as previous identify');
    }
    identifyTraits[payload.userId] = traits;
    return { ...payload, traits };
  }
}

from analytics.

Paso avatar Paso commented on June 11, 2024

I misread the setInterval as setTimeout, so that explains my confusion about that, but doesn't explain the problem.

The code was just a truncated example so it has a name and other methods, but that is one of the places where the abort function sometimes is missing.

I still don't get how the abort-function i added to the arguments when called from the heartbeat here, because method here is my identifyStart as defined above, right?

I could add a guard against the missing abort, but that seem like a recipe for dropping data so I would rather avoid it.

from analytics.

DavidWells avatar DavidWells commented on June 11, 2024

Aha I see.

We probably need a noOp function in heartbeat. Need to test this out

method({
    payload: enrichedPayload,
    config: plugins[currentPlugin].config,
    instance,
    // NoOp on queue drain
    abort: () => {}
})

......

When are you calling analytics.identify in your application? It sounds like you might be running it before all the providers are loaded. This is causing calls to get queued for the heartbeat to flush when it's back. Alternatively, it's from navigator.onLine toggling and the users internet connection going in and out...

You can try to use .ready to avoid the first case

analytics.ready(() => {
   analytics.identify('abc', { name: 'bob' })
})

from analytics.

Paso avatar Paso commented on June 11, 2024

Why shouldn't the plugins called from heartbeat be abortable?

We use a queue so it is not so easy to tell when the actual analytics.identify is being called.

If it's a problem with providers loading that would explain why the problem is so hard to reproduce, it could be the users network connection or firewall that is the problem. But shouldn't the identify (and others such as track) be queued when called before ready?

from analytics.

DavidWells avatar DavidWells commented on June 11, 2024

Why shouldn't the plugins called from heartbeat be abortable?

Yeah probably. The heartbeat was initially setup for simple edge cases though ("Just queue events to fire when network resumes").

The queued items get processed in order here

but the return values aren't checked like the main flow. abort calls just return an object with abort key and this signals downstream actions to halt. You can see queue via Analytics.getState().queue

image

Need to think about how we can get this working for the items shifted off into the queue.

I've reproduced the issue

image

from analytics.

DavidWells avatar DavidWells commented on June 11, 2024

Fixed in [email protected]

Thanks for reporting this edge case

from analytics.

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.