1
votes

I created a new custom dimension by the name of 'username' in my analytics and got the following snippet from google analytics. var dimensionValue = 'SOME_DIMENSION_VALUE'; ga('set', 'dimension1', dimensionValue);

I have an Ionic app in which I am using the Google analytics plugin : https://github.com/danwilson/google-analytics-plugin/tree/f415646

The plugin is working for reporting everything like views, etc. Now I want to track the above mentioned custom dimension.

As per the example, I entered the following in my app:

window.analytics.addCustomDimension('dimension1', uName, 
                      function(){
                        //success
                        alert('dimension data saved');
                      }, function(){
                        //error
                        alert('An error occured');
                      }
                    );

uName variable contains the correct value. If I add console log it shows correctly. Also, the success alert is shown on the app. But it is not working. This does not show any reports on my dashboard when I filter by the specified dimension.

However, the following works fine (both these lines are together, one after another):

window.analytics.trackView(currentState.name);

Has anyone successfully tracked custom dimensions for an app built with ionic / cordova ? don't know what is that I am doing wrong here.

1

1 Answers

6
votes

After going through the plugin source code I found that the 'key' parameter needs to be an integer and not a string.

Modifying the code as mentioned below solved the issue:

window.analytics.addCustomDimension(1, customValue, success, failure);

Hope this helps someone...