Reporting events and custom variables on links

84 views
Skip to first unread message

chrissky

unread,
Jul 1, 2010, 1:03:23 PM7/1/10
to google-analytics-api - GA Data Export API
First, my apologies for a long posting. And I apologize for posting to
the API group if the issues turn out this is not API specific.

Yesterday and today I did a test for a client who needs some
"multidimensional" link tracking. The approach used was to have
an onclick handler invoke async tracking with an event and with
custom variables. Two test pages were deployed with test links:

<a
href="pdf/doc1.pdf"
onclick="_gaq.push(
['_trackEvent', 'Literature','Download PDF', 'doc1', 11],
['_setCustomVar', 1, 'Type', 'Factsheet', 3],
['_setCustomVar', 2, 'Role', 'Financial Advisers', 3],
['_setCustomVar', 3, 'AssetClass', 'Bond', 3],
['_setCustomVar', 4, 'FundRange', 'fr1', 3]
);" >Factsheet 1</a>

<a
href="pdf/doc2.pdf"
onclick="_gaq.push(
['_trackEvent', 'Literature','Download PDF', 'doc2', 12],
['_setCustomVar', 1, 'Type', 'Factsheet', 3],
['_setCustomVar', 2, 'Role', 'Individual', 3],
['_setCustomVar', 3, 'AssetClass', 'Equity', 3],
['_setCustomVar', 4, 'FundRange', 'fr2', 3]
);" >Factsheet 1</a>

The second test page also has two test links. Page names are gatest1
and gatest2.
I clicked around a bit on both pages and then ran this query (in
ShufflePoint):

SELECT
METRICS ga:totalEvents,ga:uniqueEvents
DIMENSIONS ga:pagePath,
ga:eventCategory,ga:eventAction,ga:eventLabel
FROM 13844713
WHERE
TIMEFRAME yesterday
FILTER ga:pagePath =~ "gatest"

Page Path, Category, Action, Label, Total, Unique
/gatest1, Literature, Download PDF, doc2, 3, 1
/gatest1, Literature, Download PDF, doc1, 4, 2
/gatest2, Literature, Download PDF, doc4, 1, 1
/gatest2, Literature, Download PDF, doc3, 2, 1

If I also query the custom variables:

SELECT
METRICS ga:totalEvents,ga:uniqueEvents,ga:eventValue
DIMENSIONS ga:pagePath, ga:customVarValue1, ga:customVarValue2,
ga:customVarValue3, ga:customVarValue4, ga:eventCategory,ga:eventLabel
FROM 13844713
WHERE
TIMEFRAME yesterday
FILTER ga:pagePath =~ "gatest"

The results are

Page Path, Var Value 1, Var Value 2, Var Value 3, Var Value 4,
Category, Label, Total, Unique,
/gatest1, Factsheet, Advisers, Bond, fr1, Literature, doc2, 3, 1
/gatest2, Factsheet, Advisers, Swap, fr1, Literature, doc4, 1, 1

So, adding to the query any custom variable dimension (doesn't matter
which) drops the row count to two and all clicks made on the first
links in the pages are no longer reported. But note that the variables
returned are those for the FIRST link.

My assumption is that it has to do with the variable scoping, but I am
having a hard time understanding the results.

On day two, I click the links in the reverse order (in each page,
clicked 2nd link the first). The results returned now have rows for
the first links in the document. But note again the variables are
mismatched - the values are for the second link.

Page Path, Var Value 1, Var Value 2, Var Value 3, Var Value 4,
Category, Label, Total, Unique
/gatest1, Factsheet, Individual, Equity, fr2, Literature, doc1, 1, 1
/gatest2, Factsheet, Institutional, Equity, fr2, Literature, doc2, 1,
1


I'll start with the obvious question. Is this the expected behavour as
far as Google is concered? Two behavours that don't make sense to me
are:

1. Events are dropped if you ask for custom variables

I would have expected to get both events but always get the first (or
second) variable value

2. Events and variables are not in sync

For the events not dropped, I would have expected to get the variables
associated with the link tag.

Again, apologies for the long post. Hopefully it is a useful topic for
others facing similar reporting tasks.

- Chris

Nick

unread,
Jul 7, 2010, 1:22:24 PM7/7/10
to google-analytics-api - GA Data Export API
Hey Chris,

Yes this is a long post and yes it's in the wrong place :D

So Custom Vars do not send any data on their own. Instead they are
sent with the following event or pageview. So you'll want to reverse
your order and set all your custom vars first then track the event.

Also a couple of things to keep in mind:
- _gaq is asynchronously loaded. So a user could click a link before
the tracking object has loaded so no tracking could occur.
- browsers queue up http requests. So there is a race condition on
exit links (between the browser unloading the page and the request
being made. Generally you'll want to add a small timeout (100ms)
between when a user clicks the link and when they are redirected to
the destination.

-Nick

chrissky

unread,
Jul 21, 2010, 7:13:40 PM7/21/10
to google-analytics-api - GA Data Export API
I have seen the timeout in code samples. Now I understand its purpose.
Thanks for the insights Nick.

On Jul 7, 1:22 pm, Nick <api.ni...@google.com> wrote:
> Hey Chris,
>
> Yes this is a long post and yes it's in the wrong place :D
>
> So Custom Vars do not send any data on their own. Instead they are
> sent with the following event or pageview. So you'll want to reverse
> your order and set all your custom vars first then track the event.
>
> Also a couple of things to keep in mind:
> - _gaq is asynchronously loaded. So a user could click a link before
> the tracking object has loaded so no tracking could occur.
> - browsers queue up http requests. So there is a race condition onexitlinks (between the browser unloading the page and the request
Reply all
Reply to author
Forward
0 new messages