2

I am working on Google Analytics chart on my site and in the tracking code I want two add two custom dimension (One is a User ID). I am doing it this way, am I doing it right ? ga('create', 'UA-XXXX', {'userId': spUserId}); ga('set', { 'dimension1': spUserId, 'dimension2': jobAidId }); ga('send', 'pageview');

1 Answers1

1

Yes, that's correct:

ga('set', {'dimensionX': valueX, 'dimensionY': valueY, 'dimensionZ': valueZ});
ga('send','pageview');

You could also send them with other hits too:

ga('set', {'dimensionX': valueX, 'dimensionY': valueY, 'dimensionZ': valueZ});
ga('send','event', 'cat', 'action', 'label');
nyuen
  • 8,829
  • 2
  • 21
  • 28
  • Thank you so much. What is ga('send','event', 'cat', 'action', 'label'); though ? – Ahadu Melesse Aug 19 '15 at 15:35
  • That sends an event hit: https://developers.google.com/analytics/devguides/collection/analyticsjs/events – nyuen Aug 19 '15 at 15:36
  • When you use set command, it is behaved like global variable. If you set it up directly with send command, it is behaving like locally setted variable. – Jakub Kriz Aug 19 '15 at 16:54
  • 1
    To help clarify further- setting metrics and dimensions does nothing until they are sent with some kind of hit type: `pageview` and `event` are most common, but they can be sent with `timing` too (and probably even `exception`). – GreatBlakes Jun 27 '17 at 18:16