0

I'm developing an integration for Google Analytics on my website.

The idea is that a User can see the top 3 most clicked links in a leaderboard kind of widget that I'm going to show on the homepage.

I am successfully tracking outbound link clicks with Google Analytics using this little snippet:

var trackJobPostingLinkClick = function(url) {
 ga('send', 'event', 'outbound', 'click', url, {
 'transport': 'beacon',
 'hitCallback': function(){document.location = url;}
 });
}

And by triggering this function whenever a user clicks one of the links in my Job Posting Links:

<a href="https://link1" onclick="trackJobPostingLinkClick('https://link1'); return false;\">JobTitle</a>

However, I'm really interested into sending the JobTitle string (which is unique to each link) whenever I track the click because to make it a bit nicer on the eyes when I display it on my leaderboard. Is there any way that I can send the JobTitle together with the click?

So far the data I'm getting back from the API looks a bit like this:

Request:

https://www.googleapis.com/analytics/v3/data/ga?ids=[GA ID]&start-date=30daysAgo&end-date=2017年08月10日&metrics=ga%3AtotalEvents&dimensions=ga%3AeventCategory%2Cga%3AeventAction%2Cga%3AeventLabel&sort=-ga%3AtotalEvents&max-results=3&access_token=[TOKEN]

Response:

{
 ... lots of metadata...
 "rows": [
 [
 "outbound",
 "click",
 "https://link1",
 "10"
 ],
 [
 "outbound",
 "click",
 "https://link2",
 "8"
 ],
 [
 "outbound",
 "click",
 "https://link3",
 "8"
 ]
 ]
}

Ideally I'd get something back from this api like this

{
 ... lots of metadata...
 "rows": [
 [
 "outbound",
 "click",
 "https://link1",
 "Link 1 Title",
 "10"
 ],
 [
 "outbound",
 "click",
 "https://link2",
 "Link 2 Title",
 "8"
 ],
 [
 "outbound",
 "click",
 "https://link3",
 "Link 3 Title",
 "8"
 ]
 ]
 }

Which I could easily display on the leaderboard. Can anybody point me in the right direction? Is this possible?

asked Aug 10, 2017 at 18:20

1 Answer 1

2

Google Analytics standard offers 20 custom dimensions (Google 360 has 200) - these are data fields that you can name yourself and use them to enrich your data.

Custom Dimensions come in various "scopes" - hit, session, user and product; your use case would be a hit scoped dimension, where the data field is attributed to each event you send (session scope would only hold the last value in a visit, user scope only the last value for a user).

You have to create custom dimension in the GA admin panel in the property settings (look under "custom definitions"). You can assign a name that is used in the reporting interface. However to address the custom dimension in the tracking code you use the numeric index (basically the order in which your custom dimensions where created).

var trackJobPostingLinkClick = function(url) {
 ga('send', 'event', 'outbound', 'click', url, {
 'dimension1: <your value>
 'transport': 'beacon',
 'hitCallback': function(){document.location = url;}
 });
}

Custom Dimensions do not show up in the standard reports by default, but you can use them as secondary dimensions, in custom reports, via the API or in data studio (and you can also use them for segmentation or in view filters).

answered Aug 10, 2017 at 22:27
Sign up to request clarification or add additional context in comments.

2 Comments

How come that when I try to make requests to the GA API using the query explorer (ga-dev-tools.appspot.com/query-explorer) I get no data when I try to query one of my custom dimensions, but I get data if I drop all the custom dimensions?
Because the query returns data only when there are values recorded for that specific combination of metrics. Meaning as long as there are no hits that have values for the custom dimension (might take up to 24 hours before the values show up) including the custom dimension in your query will return nothing (custom dimensions don't have a "not set" default value, they are simply not there until some data has arrived).

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.