angulartics / angulartics2

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

setUserProperties to GA could be setup with 'user_properties' #465

Open phillipwildhirt opened 1 year ago

phillipwildhirt commented 1 year ago

I'm submitting a update/feature request for GA4.



New GA4 requires an object {user_properties: {prop1: 'value', prop2: 'value'}} set in the 'config' script in order for custom dimensions to be picked up as User scoped custom dimensions.

Currently setDimensionsAndMetrics() in ga cleans out top level dimensions and metrics, such as 'dimension1', 'dimension2', which will be deprecated with new GA4, but user_properties sent to setUserProperties is being attached using this, and they are buried, and not cleaned.



Excerpt from src/lib/providers/ga/ga.ts, line 224:

    // clean previously used dimensions and metrics that will not be overriden
    this.dimensionsAndMetrics.forEach(elem => {
      if (!properties.hasOwnProperty(elem)) {
        ga('set', elem, undefined);

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




I believe a rethink of the setUserProperties behavior is needed, as I'm having a hard time getting consistent user_properties delivered to the event_track every time.


Environment:

Angular CLI: 13.2.5 Node: 16.14.0 Package Manager: npm 8.3.1 OS: darwin x64

Package Version

@angular-devkit/architect 0.1302.6 @angular-devkit/build-angular 13.2.5 @angular-devkit/core 13.2.6 @angular-devkit/schematics 13.2.5 @angular/cli 13.2.5 @angular/elements 14.0.0 @schematics/angular 13.2.5 rxjs 7.5.7 typescript 4.5.5