angulartics / angulartics2

Vendor-agnostic analytics for Angular2 applications.
MIT License
1.01k stars 193 forks source link

user properties should not be reset on each event #318

Open recaro opened 5 years ago

recaro commented 5 years ago

Regression of #108

Dimensions set by setUserProperties are being cleared on each event due to this line: https://github.com/angulartics/angulartics2/blob/6fc83a4914152feca6c701dc685b46f554dece11/src/lib/providers/ga/ga.ts#L227

In our case we set the dimensions with setUserProperties once per user session and want those to be sent with each event/pageview - we don't want to provide dimensions for each call.

Suggestion: Make sure that dimensions set by setUserProperties are not removed by #108

cvaliere commented 5 years ago

guys, I don't understand how this lib is supposed to work

when setting user properties, I definitely don't want them to be reset on each event, I think it doesn't make sense at all

I see there are 2 methods setUserProperties and setUserPropertiesOnce, which makes me think that the 1st one resets on each event, whereas the 2nd one doesn't; but looking at implementations, it seems that most of the providers don't implement setUserPropertiesOnce, or have the same implementation as setUserProperties

can someone help me understand? :)

chadbr commented 5 years ago

even more confusing to me is this code:

https://github.com/angulartics/angulartics2/blob/6fc83a4914152feca6c701dc685b46f554dece11/src/lib/providers/ga/ga.ts#L239

    // add custom dimensions and metrics
    Object.keys(properties).forEach(key => {
      if (
        key.lastIndexOf('dimension', 0) === 0 ||
        key.lastIndexOf('metric', 0) === 0
      ) {
        ga('set', key, properties[key]);

        this.angulartics2.settings.ga.additionalAccountNames.forEach(
          (accountName: string) => {
            ga(`${accountName}.set`, key, properties[key]);
          },
        );
        this.dimensionsAndMetrics.push(key);

this only calls ga.set on properties that include 'dimension' and 'metric' ?? We have lots of dimension names -- this code makes no sense to me.

why not call ga.set for all the properties?

pasevin commented 4 years ago

@chadbr everything makes sense here. You're referring to 'analytics.js' provider. It's custom dimensions implementation is different from 'gtag.js'.

The main difference is that gtag.js has custom_map option which allows mapping your custom dimensions and then use them as you expect. On the other hand analytics.js only understands dimensionX format.

Ref for gtag.js provider with customMap here