Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google universal analytics dimensions and modifying the tracking code

I am using google universal analytics within react. React is probably irrelevant for this question but just for information I am using react-ga plugin.

Using this document I created 3 dimensions; https://support.google.com/analytics/answer/2709829#zippy=%2Cin-this-article

The dimensions are company, property, and space.

At the end of that tutorial document it says "you must also modify your tracking code" and provides a link to another document but that document does not explain or even mention 'modifying the tracking code'.

I have the dimensions created and I set them in the code using react ga's method:

ReactGA.set({company: "Acme123"})

and in the console I get Set called on unknown field: "company".

This is the output from react ga/google analytics to I am comfortable react-ga is executing the google UA commands properly

analytics_debug.js:26 Running command: ga("create", "UA-XXXXXXXX-1", "auto")
analytics_debug.js:26 Creating new tracker: t0
analytics_debug.js:26 Auto cookieDomain found: "none"
analytics_debug.js:26 Running command: ga("set", {company: "Acme123"})
analytics_debug.js:26 Set called on unknown field: "company".
analytics_debug.js:26 Running command: ga("set", {property: "property name here"})
analytics_debug.js:26 Set called on unknown field: "property".
analytics_debug.js:26 Running command: ga("set", {space: "id # here"})
analytics_debug.js:26 Set called on unknown field: "space".
analytics_debug.js:26 Running command: ga("send", {hitType: "pageview", page: "/profile/34733494-ec46-48ed-b2ae-0ffef6d2499e"})

What do I need to do to the tracking code (as doc says to "modify" it or new dimensions won't work)?

FYI - I see the pageviews in the google web UI so I know this is all basically working but I need to save some arbitrary data to be able to filter on it later when querying report data for a custom data report display (outside and separate from the google analytics web interface).

like image 916
Nick Licata Avatar asked Jul 19 '26 00:07

Nick Licata


1 Answers

When you set custom dimensions, you don't use their name, you instead use their index. For instance, in your example, if company is configured in the first position in your GA account, you would set it like so: ReactGA.set({dimension1: "Acme123"})

You can find the official guide here: Custom Dimensions and Metrics  |  Analytics for Web (analytics.js)

like image 192
bogdan_b Avatar answered Jul 21 '26 13:07

bogdan_b



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!