angulartics icon indicating copy to clipboard operation
angulartics copied to clipboard

Providing same object to multiple tracking calls causes problems

Open ljwagerfield opened this issue 10 years ago • 5 comments

It appears that Angulartics mutates objects passed as parameters to eventTrack and setUserProperties calls. This results in malformed tracking information being sent to the analytic web service(s).

To reproduce:

var properties = {'foo': 'bar'};
$analytics.eventTrack('some event', properties);
$analytics.setUserProperties(properties);

This will result in the payload for the initial call being sent down-the-wire as the payload for the second call, at least when observing KISSmetrics. This includes timestamps, which caused the real problem for us.

ljwagerfield avatar Dec 16 '14 18:12 ljwagerfield

Good catch, thank you. Anyone feeling like submitting a PR for this?

luisfarzati avatar Jul 18 '15 01:07 luisfarzati

Random questions:

  • Why aren't you calling setUserProperties first?
  • Does sending user props cause mutations?
  • Instead of making every library that takes an object, clone the arguments just in case you choose to reuse it, what are your thoughts about you just doing $analytics.eventTrack('some event', angular.copy(properties)); instead?

ProLoser avatar Sep 24 '15 06:09 ProLoser

@ljwagerfield do you have any update/progress?

timelf123 avatar Jan 12 '16 21:01 timelf123

I've also noticed that while creating own plugin. Here is the example of inconsistency from two different plugins.

// angulartics-segment.js
$analyticsProvider.registerSetUserProperties(function (userId, traits, options, callback) {
  try {
    analytics.identify(userId, traits, options, callback);
  } catch (e) {
    if (!(e instanceof ReferenceError)) {
      throw e;
    }
  }
});

--

// angulartics-mixpanel.js
$analyticsProvider.registerSetUserProperties(function (properties) {
  mixpanel.people.set(properties);
});

websirnik avatar Dec 07 '16 15:12 websirnik

I'm not really sure how to handle this. At one point we discussed wrapping analytics.js from segment since they abstract away all of the differences between providers.

@angulartics/core thoughts or do you remember our discussion from way back when?

timelf123 avatar Dec 15 '16 19:12 timelf123