Analytics
2.2K members online now
2.2K members online now
Dive into multiple domain (Cross/Sub) tracking, implementing Ecommerce and Enhanced Ecommerce, setting up Event tracking, and Universal Analytics code.
 
Guide Me
star_border
Reply

Issue enabling analytics tracking to link for JAVA dropdown content

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Analytics working as expected on page for all links except for JavaScript links triggering dropdown content on the page.
We have enabled Enhanced Link Attribution which states "Track buttons, menus, and actions driven by javascript.", and added ga('require', 'linkid'); analytics code as described on the Analytics Help page (https://support.google.com/analytics/answer/2558867?hl=en).
The link trigger for the dropdown content has been given the id "borrower", example: <p id="borrower" class=loan>Who will be the borrower?</p>.
After following the Google Analytics Help steps the java drop down content analytics are still not working.
What are we missing?

Re: Issue enabling analytics tracking to link for JAVA dropdown content

Follower ✭ ☆ ☆
# 2
Follower ✭ ☆ ☆
Greetings VSAC,

I'm having some trouble understanding exactly what the problem you are encountering is. Is Analytics not registering clicks on links like "<p id="borrower" class=loan>Who will be the borrower?</p>"?

Are you using a tag management solution, or are you relying on on-page code?

Let me know!

Cheers,

Bogdan

Re: Issue enabling analytics tracking to link for JAVA dropdown content

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭
Thank you for the response Bogdan,
Yes we are relying on on-page code.

Re: Issue enabling analytics tracking to link for JAVA dropdown content

Follower ✭ ☆ ☆
# 4
Follower ✭ ☆ ☆
Hi VSAC:
Two updates will help solve this issue.
1) Provide a unique id for each element in your JavaScript drop down. and
2) Include an "a" tag for the links - this is the not required but will help.
Best,
Jay

Re: Issue enabling analytics tracking to link for JAVA dropdown content

Visitor ✭ ✭ ✭
# 5
Visitor ✭ ✭ ✭
Hi Jay thanks for the feedback,
Here is the page where I am trying to add the analytics tracking.
http://services.vsac.org/wps/wcm/connect/vsac/vsac/pay+for+college/funding+sources/loans/vsac+-+pay+...
For instance we want to track the clicks on the "Who will be the borrower" link users click to see the drop down content. Previously I added the id code below but it did not seem to work.
<p id="borrower" class=loan>Who will be the borrower?</p>.
What am I missing?

Re: Issue enabling analytics tracking to link for JAVA dropdown content

[ Edited ]
Follower ✭ ☆ ☆
# 6
Follower ✭ ☆ ☆

Hi VSAC,

 

I tried taking a peek behind the scenes to see what you have already tried to get a better understanding of why it might not be working, but I was unable to find any on-page code. Let me know what specifically you have tried and I will review.

 

In the meantime, you could try the approach below. You could either hard code this script on the page in a self executing anonymous function or host it on your server and call the script at the top of the page. Here is an example of what the function might look like:

 

(function(){
	//using # indicates jQuery will look for the element ID
	jQuery('#borrower').click(function(){
		ga('send', 'event', 'eventCategory', 'eventAction', 'eventLabel')
	});

	//using . indicated jQuery will look for the element class
	jQuery('.loan').click(function(){
		ga('send', 'event', 'eventCategory', 'eventAction', 'eventLabel')
	});
})()

Let me know if this helps!

 

Cheers,

 

Bogdan

Re: Issue enabling analytics tracking to link for JAVA dropdown content

Visitor ✭ ✭ ✭
# 7
Visitor ✭ ✭ ✭
Thank you Bogdan I will review my code.

Re: Issue enabling analytics tracking to link for JAVA dropdown content

Visitor ✭ ✭ ✭
# 8
Visitor ✭ ✭ ✭
Hi Bogdan,
Thank you for your suggestions. My code has been adjusted (see the url above) but the "Who will be the borrower" and "How soon can you begin repaying your loan" dropdown links are still not capturing analytics. Do you have any suggestions as to what additional code adjustments need to be made?

Re: Issue enabling analytics tracking to link for JAVA dropdown content

Visitor ✭ ✭ ✭
# 9
Visitor ✭ ✭ ✭
Hi Jay,
My analytics code has been updated for the page,
http://services.vsac.org/wps/wcm/connect/vsac/vsac/pay+for+college/funding+sources/loans/vsac+-+pay+...
Unfortunately the "Who will be the borrower" and "How soon can you begin repaying your loan" drop down links are still not capturing analytics. Can you provide and assistance on how to fix this issue?
Regards,

Re: Issue enabling analytics tracking to link for JAVA dropdown content

[ Edited ]
Follower ✭ ☆ ☆
# 10
Follower ✭ ☆ ☆

Hi VSAC:
Bogdan was headed in the right direction. You have this code (on line 22) that hides and unhides on a click:

<script type="text/javascript">
$(document).ready(function()
{ //hide the all of the element with class answer
$(".details").hide();
//toggle the componenet with class question
$(".loan").click(function()
{
$(this).next(".details").slideToggle(200);
});
});
</script>



What you will want to do is send the GA event when this code runs. So you can change it to this:

<script type="text/javascript">
$(document).ready(function()
{ //hide the all of the element with class answer
$(".details").hide();
//toggle the componenet with class question
$(".loan").click(function()
{
$(this).next(".details").slideToggle(200);
ga('send', 'event', 'Link Click', $(this).children("a").attr("name"));
});
});
</script>



The code:

$(this).children("a").attr("name")

will either be "borrower" or "repaying" depending on which link the user clicks.
You will then see these in the Events reports in Google Analytics.

Let me know how this works!
Best,
Jay