jaitaiwan
jaitaiwan

Reputation: 310

Google Analytics Uses Asterix in URL

In google's new Measurement Protocol they have the ability to send custom dimensions through to google analytics.

I've setup the custom dimensions as per Google's Instructions and I've been given two indexes:

I have these setup to record on a hit-by-hit basis and I'm using PHP to send the data to google.

In their specifications they have this: cd[1-9][0-9]* and the example for it is: cd[1-9][0-9]*=Sports the value obviously being Sports.

What perplexes me is that I am given a single index starting at 1 which accounts for the first parameter and not the second. Even further is their use of the asterix which I understand is a reserved character but what it's purpose is in this case I have no clue.

Because I am using PHP I am trying to setup the query strings by passing an object to http_build_query which I'm sure won't produce and asterix unless it's part of a string so this confuses me even more.

What I have tried is to send cd[1]=value and cd[1][0]=value which don't appear to be coming through. I'm yet to try cd[1][0]*=value but that makes me think I am barking up the wrong tree.

So the question is, how am I meant to be passing custom dimensions through to Google Analytics correctly using their Google Measurement Protocol? And if I need to use an asterix, is there a way of achieving this using the above methods or will I have to append to the query string manually?

Thanks!

Upvotes: 1

Views: 191

Answers (1)

MisterPhilip
MisterPhilip

Reputation: 2452

In this case, think of those specifications as regex strings. You'll have the string "cd" plus a digit plus possibly another digit (think ? instead of *).

Per your example, you'll have 2 URL parameters as such:

cd1=OrderIDA&cd2=OrderIDB

If you were to use dimension 15, you'd end up with:

cd15=Foobar

Same goes with metrics (#1 = 1 and #15 = 1,625)

cm1=1&cm15=1625

Upvotes: 1

Related Questions