Google Analytics Custom Dimension + Metrics improvements

analytics

#1

Hi Jovo Team,
after using Google Analytics for a longer time and building some bigger applications i find custom metrics and dimensions are both: biggest strength and biggest weakness. My proposal is to fix this by allowing to map them to certain indices and validate if all needed definitions are set.

Custom Definitions allow us to tell analytics new contents like:

  • In which game is my user?
  • How rank different games against each other?
  • How often users are reaching a certain point in our flow?

There are many questions google Analytics can answer for specific voice platforms. For example Alexa is sending SessionEndedRequests containing valuable information why users are leaving a skill. Paired with the requests Google Analytics is sending, you can easily find out which states, intents (or other skill specific content) are producing the most max_reprompts for example. Therefore my last Pull Request enhanced Google Analytics with the feature to automatically track endReasons via customMetrics.
All the developer (after creating a new Google Analytics project ) has to do is creating five custom metrics in a specific order.

This works fine as long as you want to enhance analytics with new features like tracking unhandled counts. Assume a user project has the fix custom metrics mentioned above set to index 1 to 5. On index 6 and 7 are project specific metrics. This could be something like a user rank and money collected inside the game.
The new feature wants to track intents routed to unhandled on index 6. This would result in polluting the users rank statistic collected before. He would not even recognize it before his data is worthless. Therefore the approach used before would result in a plugin which is hard to enhance. Addiontionally when applications start to grow there could be limitations with the free contingent of custom definitions allowed in gAnalytics.
A developer should have options to choose which metrics and dimensions are tracked and assign them to a free slot.

I prepared a pull request to reach this. Inside the config metric and dimensions are mapped from their name to a target index via string, number tubles like here:

systemMetrics: [

        ['Stop', 1],

        ['ERROR', 2],

        ['EXCEEDED_MAX_REPROMPTS', 3],

    ...

They are loaded into a map when the application starts. My suggestion would be to validate if each metric and dimension needed by the jovo-analytics-googleAnalytics plugin is defined there and that there are no definitions mapped to the same index. If there is no index defined for the “Stop” metric for example the skill would prompt the user to insert it (or set it to 0 if it should not be tracked).
Although it would be possible to simply ignore not set definitions I prefer the approach above because it makes sure that tracking is not disabled due to typos or config mere issues.
What do you think @jan @Max @AlexSwe ? Should there be a config value to not validate system definitions?

One more questions is on the jovo$googleAnalytics object. This was set to the instance of the GoogleAnalytics Object before, which allowed developers to extend it without having to write a new interface and attach it to the jovo object. Now visible functions are manually set in the setGoogleAnalyticsObject hook. What is the reason for this and how would you recommend to enhance the methods offered there (wouldn’t do access modifiers a similar job tho shadow properties?). @Max


#2

Hi @Andre, Thanks a lot for your suggestions! I’m not too deep into the development of the Google Analytics plugin, but will discuss with the team. Would your PR be a breaking change?

It might also be a great idea to add @theBenForce to this thread, he’s been extending the Google Analytics plugin as well: https://github.com/jovotech/jovo-framework/pull/905


#3

Hi @jan, my suggested version above would be a breaking change. This is because a user is prompted to add metrics and dimensions set by system to his config as long as there are missing some values. A different version could skip all definitions which are not set there. I prefer version one because if you update a project (or a bunch of projects) it is likely to miss some entries. You would have one destination (your config) where you have a good overview of all metrics and dimensions (and the index they are targeting).
Like said above there could be a config value to switch between both modes.

For the same reason an even better solution would allow the user to define his own custom definitions and metrics at the same place in the config. The developer does the mapping from metric/dimension name only once in the development process. Afterwards he/she could set dimensions and metrics by name. This results in ten advantages:

  • make the code more readable
  • no mess up of analytics due to typos (momentously choosing index 2 instead of 3 could make your analytics data useless)
  • possibility to move your analytics project without having to change the code
  • analytics check for conflicts in own definitions and system definitions

For now there are two new methods setSystemDimension and setSystemMetric which could be altered to something like setCustomMetricByName. To additionally enable intellisense we declare these methods to add our own project specific dimensions and metrics (see screenshot). Now when typing setSystemMetric(' you get all available metrics by name.

I already studied the pull request from @theBenForce and will use the optimize feature in future projects. Nonetheless it seems to me than one part of the pull request was necessary due to manually set $googleAnalytics object i mentioned in my last post. If $googleAnalytics would be an instance of the GoogleAnalytics object you could access the visitor property which gives access to the whole universal-analytics npm package jovo-analytics-googleAnalytics depends on. this.$googleAnalytics.visitor.set( already offered options to set properties (like ‘browser’ ‘userId’ etc.) in the past.

Maybe we could have a call to address the open question @jan?


#4

So @jan told me that the focus will be to avoid a breaking change and make sure the behavior for developers won’t change by default after updating. I will do that and make a pull request.

@Max can you tell if it is ok to switch the jovo.$googleAnalytics object back to the instance of the object? Like argumented above this would make it easier to extend it and dismiss the need to define the interface after making new instance methods.


#5

@jan @AlexSwe I requested a pull request. Could you have a look if this is ok with you?