Below is the code that I use to set and id for the 'View' and another as custom diamention in my android app. Both these are implemented at the tracker level, so that with every GA call this these values are also set.
tracker.set("&uid", userId); //for view
tracker.set("&CustUserID", custID); //for custom dimension
Now the issue is that the tracker set for view works, but for custom dimension its not working. CustUserID is the name of the dimension I have created.
You need to correct your code to properly set the custom dimension with appropriate dimension index. Detailed documentation found here.
tracker.setCustomDimension(4, custId);
Where your custom dimension you created is indexed at 4.
But if you insist on using the measurement protocol syntax:
tracker.set('&cd4', custId);
CustUserID is not in the defined parameters so it will not work.
Related
I'm using this code for setting custom dimension
tracker.send(new HitBuilders.ScreenViewBuilder()
.set("&cd", "Home Screen")
.build()
);
also tried this :
mTracker.send(new HitBuilders.ScreenViewBuilder()
.set("&cd1", "premiumUser")
.build()
);
and for getting value :
mTracker.get("&cd1");
but nothing work ,I have no idea how to get the current set value for this dimension.
I used alot of resources but nothing works. Also I followed all steps for setting custom dimensions in my Account.
Any ideas?
Your code sets the custom dimension to a single hit and then reads from the tracker object. That's the reason reads don't work.
Assuming you want to add the "premiumUser" custom dimension to all subsequent hits, and its dimension index is 1, your code should be as follows:
mTracker.set("&cd1", "premiumUser");
Then you should be able to read it from tracker object:
mTracker.get("&cd1");
You can find documentation for Tracker here.
As a side comment, if you need to set a custom dimension for a single hit, there is a different method in HitBuilder which is recommended for this purpose:
mTracker.send(new HitBuilders.ScreenViewBuilder()
.setCustomDimension(1, "premiumUser")
.build()
);
I want to set user level custom variables using google analytics in android
I can see there is lack of documentation and demo for this I want to know how to set custom variable using GA and I am referring to following link
https://support.google.com/analytics/answer/2709828#scope
but it is not helpfull at all code given in it is not in java and very confusing
If anyone has proper sample related to it please share
And it is not clear at all how much time it will take to reflect these changes on GA dashboard there is no clarity while using google analytics.
Also there a sample a code given
// Get tracker.
Tracker t = ((AnalyticsSampleApp) getActivity().getApplication()).getTracker(
TrackerName.APP_TRACKER);
t.setScreenName("Home Screen");
// Send the custom dimension value with a screen view.
// Note that the value only needs to be sent once.
t.send(new HitBuilders.ScreenViewBuilder()
.setCustomDimension(1, "premiumUser")
.build()
);
Now can anyone explain what is value 1 stands and it comes from where for in above call and why I need to call setScreenName
Also I have referred below link as well but does not give any clear idea
https://support.google.com/analytics/answer/2709829?hl=en&ref_topic=2709827
Also I tried to create custom variable I observed that one custom variable Demographic is already there I guess it is default created by GA so now my custom variable will start with index 2 or 1 that is also a confusion.
Custom Dimensions and metrics are identified by an index: 1 to n. The first Custom dimension you create will have an index of 1. Before you can send custom dimension and metric values to Analytics, they must first be defined in an Analytics property in the Analytics UI or through the Management API. Each Analytics property has 20 available indices for custom dimensions, and another 20 indices available for custom metrics.
The sample you used is sending a screen view hit (hence why it is setting the screen name) and sending a value to the first custom dimension. However you can send the information on any event type you'd like. For example:
// Get tracker.
Tracker t = ((AnalyticsSampleApp) getActivity().getApplication()).getTracker(
TrackerName.APP_TRACKER);
// Build and send an Event.
t.send(new HitBuilders.EventBuilder()
.setCategory(getString(categoryId))
.setAction(getString(actionId))
.setLabel(getString(labelId))
.setCustomDimension(1, "premiumUser") // Set the first custom dimension value to premiumUser for this event.
.build());
When you query for the value of the custom dimension with the Analytics Reporting API you will identify the custom dimension by index aswell, ga:dimension1.
Apart from registering in Android
Bundle().apply {
putString("Business", "NONE")
putString("PageVertical", "NONE")
FirebaseAnalytics.getInstance(context).setDefaultEventParameters(this)
}
Do not forget to register at Google Analytics UI
Custom parameters: Custom parameters can be used as dimensions or metrics in Analytics reports. You can use custom dimensions for non-numerical event parameter data and custom metrics for any parameter data better represented numerically. Once you've logged a custom parameter using the SDK, register the dimension or metric to ensure those custom parameters appear in Analytics reports. Do this via: Analytics > Events > Manage Custom Definitions > Create Custom Dimensions
Read more
I am able to pass events to google Tag Manager v4 but the custom dimensions are not set. I have not been able to find ANYTHING on examples how to do this. The custom dimensions are setup correctly.
the code I'm using is:
DataLayer mDataLayer = ContainerHolderSingleton.getDataLayer();
mDataLayer.pushEvent("clip-start",DataLyaer.mapOf("Network","network value here"));
It should be this simple. I've setup the custom dimensions to be Custom Dimension index 1, in the admin it's setup as index 1.
Doesnt' help that googles sample code doesn't tell me much either: This is the generated code that is generated when I input the custom dimesnion in the admin. What is "tracker", or Fields.. they dont tell me which import will work with this.
String dimensionValue = "SOME_DIMENSION_VALUE";
tracker.set(Fields.customDimension(1), dimensionValue);
So ultimately, how do I pass the custom Dimension values through the data Layer to GTM.
It is probably because you may not have added custom dimensions into your google analytics tag in tag manager. Add the custom dimensions with parameters with values. The ids should match the ones in analytics.
Hope that helps
The way I solved this was to use the GoogleAnalytics Tracker like this:
tracker.set("&cd1", "new video title");
tracker.set("&cd2", "vidoe type");
tracker.set("&cd3", "access");
&cd1, &cd2 etc is the way these constant fields are passing custom dimensions to the back end.
Make sure you double check the sample code for reusing and downloading a container. I had mucked with it and that was stopping me from getting the new container, thus also not getting new values. Copy the sample code verbatim.
How can I attach a custom metric value to HitBuilders.TransactionBuilder in the following fashion? I want to associate a transaction with a value.
tracker.send(new HitBuilders.TransactionBuilder()
.setOtherAttributes(...)
.setCustomMetric(1, 10)
.build());
The rest of the data are successfully sent, but the custom metric is always 0.
It seems your code is correct. You can try to setCustomDimension instead of setCustomMetric, you only have to transform float to string.
Your code is correct. What you need to check is the server side reports you build.
Make sure you created a Custom metric in Admin - Custom Definitions - Custom metrics. Once created, custom metrics will initially appear with a 3 to 4 hours delay on the server. Give them some time to appear there. Finally, you need to create a report to see the result. Make sure you choose the right time intervals and don't add too many metric and filters, otherwise you won't see data. Make first reposts as simple as possible. I hope this helps.
The problem was with that the scope of the custom metric was not Hit and that I was looking at a custom report widget matched by Product. The value appeared when I changed the column.
Following this guide I've added GA to my app and it works just fine. To send hits, I use the following code:
getGaTracker().set(Fields.SCREEN_NAME, "Screen Name");
getGaTracker().send(MapBuilder.createAppView().build());
But what if I want to set more parameters to this Tracker? If you check Fields.class, you will se lots of parameters that can be set.. like in hitParameters.put(Fields.HIT_TYPE, "appview");, can I set any arbitrary value for HIT_TYPE? Where will this appear in my stats, and what are the other fields for?
I also want to find out if I can add more parameters to 'getGaTracker().set()', in a way to add more logging levels like when logging Events...
Again from the DevGuide we have this snippet:
Tracker t1 = GoogleAnalytics.getInstance(this).getTracker("UA-XXXX-1");
// Trackers may be named. By default, name is set to the property ID.
Tracker t2 = GoogleAnalytics.getInstance(this).getTracker("altTracker", "UA-XXXX-2";)
So the Property ID isn't the only possible parameter for instantiating a Tracker. It would be great to have some docs do check all uses for it.
The only thing I found so far is this page