Analytics
2.1K members online now
2.1K members online now
Dive into multiple domain (Cross/Sub) tracking, implementing Ecommerce and Enhanced Ecommerce, setting up Event tracking, and Universal Analytics code.
 
Guide Me
star_border
Reply

Issues with setting Custom Variable

[ Edited ]
Follower ✭ ☆ ☆
# 1
Follower ✭ ☆ ☆

I am using analytics.js.

I want to track the gender of the person filling up the form. The gender appears in a dropdown list.

 

This is what I am doing:

In GA - I have created a Custom Dimension under Property settings.  I named it Gender.

 

1. Capturing value for selected option.

var dms = $('#gender :selected').val();

2. Storing this value in a variable called dms.

3. Submitting form data through AJAX.

4. In the success callback using this code:

ga('set', 'dimension1', dms);
ga('send','pageview','/page/');

 I don't get any error but in GA Custom Dimensions shows nothing.

1 Expert replyverified_user
1 ACCEPTED SOLUTION

Accepted Solutions
Marked as Best Answer.
Solution
Accepted by topic author Vipul B
December 2016

Issues with setting Custom Variable

[ Edited ]
Follower ✭ ✭ ☆
# 10
Follower ✭ ✭ ☆

Yes, you can also send dimensions, not only metrics. 

you can simply send it with an event 

 

ga('send', 'event', 'category', 'action', {
 
'dimension1': dms
});

 

View solution in original post

Issues with setting Custom Variable

Follower ✭ ✭ ✭
# 2
Follower ✭ ✭ ✭

Hi,

You are passing custom dimension but you are asking for custom variable Smiley Happy 

 

Thanks

Sura

Issues with setting Custom Variable

Top Contributor
# 3
Top Contributor

As @Suradha P mentioned, you should be using "Custom Dimension" in your reports to view that information, not Custom Variable (this is deprecated. I think it shouldn't even be available in the UI anymore as it was used with the legacy GA tracking!). Depending on what scope you have configured (hit, user, session, product), you should be able to pull in that dimension in your standard or custom reports.

Nicky Yuen, Google Analytics Top Contributor
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here.
Find me on: Google+ | LinkedIn

Issues with setting Custom Variable

Follower ✭ ☆ ☆
# 4
Follower ✭ ☆ ☆

Oops! That's an error from my side. Sorry.

Issues with setting Custom Variable

Follower ✭ ☆ ☆
# 5
Follower ✭ ☆ ☆

Yup, that's an error from my side Nicky.

But do you think the implementation is correct?

Also won't the pageview be counted twice after setting the dimension since native GA code already sends a pageview on page load?

Issues with setting Custom Variable

Follower ✭ ✭ ✭
# 6
Follower ✭ ✭ ✭

Hi Vipul,

Your implementation looks alright. And it wont double count your page view.

 

try using console.log(dms) ; just before you pass the value to the ga as dimension. So you know whether your code picks correct value in you google chroms developer tools (press f12) under console section.

 

hope this helps

 

Thanks

Sura

Issues with setting Custom Variable

Follower ✭ ☆ ☆
# 7
Follower ✭ ☆ ☆

Thanks Suradha! The code is working fine as far as capturing the selected value is concerned. Maybe, GA takes time to display those values. I'll get back on this thread after re-running the test.

 

Also are you sure pageview would not be counted twice? Do I need to send a pageview at all?

Issues with setting Custom Variable

[ Edited ]
Follower ✭ ✭ ☆
# 8
Follower ✭ ✭ ☆

 You need to call a send, otherwise, just setting the dimension won't send it to GA. But instead of sending a pageview, you can send an event. Otherwise, the pageview will be sent twice (that's because, as you explained, you're submitting the form through AJAX so the user stays in the same page where you already sent a pageview when it first loaded).

 

Also, data about dimensions is usually available the next day (not the same day)

Issues with setting Custom Variable

Follower ✭ ☆ ☆
# 9
Follower ✭ ☆ ☆

Thanks @Anca Banica !

I did run an experiment to test pageviews count and indeed got two pageviews!

Sending an event will be a good option [Thinking Face]

As mentioned on Google Dev page, we can send custom metric via event. Can we send dimension as well?

I am also thinking to set dimension before event and then send metric value via event.

Will it be a good approach?

Marked as Best Answer.
Solution
Accepted by topic author Vipul B
December 2016

Issues with setting Custom Variable

[ Edited ]
Follower ✭ ✭ ☆
# 10
Follower ✭ ✭ ☆

Yes, you can also send dimensions, not only metrics. 

you can simply send it with an event 

 

ga('send', 'event', 'category', 'action', {
 
'dimension1': dms
});