Analytics
3.1K members online now
3.1K members online now
Learn how to set up goals and Ecommerce tracking, verify accuracy of attribution traffic sources, and discuss funnel visualization, Multi-Channel Funnels, the Goal Flow Report, and Enhanced Ecommerce
 
Guide Me
star_border
Reply

Code of Event Tracking of mailto clicks for Universal Analytics

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hi guys,

 

I know that this is not a new topic. I've been searching for a detailed solution for a while, but could not find a satisfying answer. I am looking for a complete and correct code example to track the number of clicks on mailto links on a webpage using Universal Analytics Event Tracking, but not the Tag Manager.

 

Would anybody be so kind to provide me with a complete code example on this one, including the info about the correct place and best practice to put the code snippet in the source code of the respective page(s)?

 

Thanks a lot in advance for your answers!

 

Urs

1 Expert replyverified_user
1 ACCEPTED SOLUTION

Accepted Solutions
Marked as Best Answer.
Solution
Accepted by topic author Urs A
November 2015

Re: Code of Event Tracking of mailto clicks for Universal Analytics

Top Contributor
# 4
Top Contributor
Hi, Urs,

There's not a whole lot of information for me to go on, so this is pretty generic: Assuming this is your mailto link:

<p>Email us here at <a href="mailto:someone@example.com?Subject=Hello" id="mailto">email address</a></p>

You have the following options:

1. Putting the click handler directly in the anchor:
<p>Email us here at <a href="mailto:someone@example.com?Subject=Hello" target="_top" id="mailto" onclick="ga('send', 'event', 'click', 'mailto');">email address</a></p>

2. Using a click listener, given that the mailto link has an id:
$('#mailto').click(function(){
ga('send', 'event', 'click', 'mailto');
})

This would be place near the top of the page or you could place it anywhere but should be loaded on $(document).ready().

3. Defining a global function that can be placed again at the top of the page:
function mailto(){
ga('send', 'event', 'mailto', 'click');
}
and then called again directly in the mailto link:
<p>Email us here at <a href="mailto:someone@example.com?Subject=Hello" target="_top" id="mailto" onclick="mailto();">email address</a></p>

There are probably more options, too, but I think these are the most common.

Hope something here helps.
Nicky Yuen, Google Analytics Top Contributor
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here.
Find me on: Google+ | LinkedIn

View solution in original post

Re: Code of Event Tracking of mailto clicks for Universal Analytics

Top Contributor
# 2
Top Contributor
Hi Urs,

What are your requirements for a satisfying answer? Does your site use jQuery, or is it native JS? Are your mailto link structures/HTML/CSS consistent throughout your whole site? Do you use specific IDs or Classes for your links?

Thanks
Nicky Yuen, Google Analytics Top Contributor
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here.
Find me on: Google+ | LinkedIn

Re: Code of Event Tracking of mailto clicks for Universal Analytics

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭
Hi Nicky,

Requirements would be to get a code snippet that does the job plus the instruction about where to exactly implement it in the sourcecode. Yes, I use jQuery and the structure/html/css are consistent. Not using special IDs nor classes for the mailto links, they are simply put in a common textblock class. Tnx!
Marked as Best Answer.
Solution
Accepted by topic author Urs A
November 2015

Re: Code of Event Tracking of mailto clicks for Universal Analytics

Top Contributor
# 4
Top Contributor
Hi, Urs,

There's not a whole lot of information for me to go on, so this is pretty generic: Assuming this is your mailto link:

<p>Email us here at <a href="mailto:someone@example.com?Subject=Hello" id="mailto">email address</a></p>

You have the following options:

1. Putting the click handler directly in the anchor:
<p>Email us here at <a href="mailto:someone@example.com?Subject=Hello" target="_top" id="mailto" onclick="ga('send', 'event', 'click', 'mailto');">email address</a></p>

2. Using a click listener, given that the mailto link has an id:
$('#mailto').click(function(){
ga('send', 'event', 'click', 'mailto');
})

This would be place near the top of the page or you could place it anywhere but should be loaded on $(document).ready().

3. Defining a global function that can be placed again at the top of the page:
function mailto(){
ga('send', 'event', 'mailto', 'click');
}
and then called again directly in the mailto link:
<p>Email us here at <a href="mailto:someone@example.com?Subject=Hello" target="_top" id="mailto" onclick="mailto();">email address</a></p>

There are probably more options, too, but I think these are the most common.

Hope something here helps.
Nicky Yuen, Google Analytics Top Contributor
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here.
Find me on: Google+ | LinkedIn

Re: Code of Event Tracking of mailto clicks for Universal Analytics

Visitor ✭ ✭ ✭
# 5
Visitor ✭ ✭ ✭
That's awesome Nicky! Thank you very very much. I am sure these approaches work for my project.

Kind regards and have a good day, Urs

Re: Code of Event Tracking of mailto clicks for Universal Analytics

Visitor ✭ ✭ ✭
# 6
Visitor ✭ ✭ ✭
Hi Urs,

Can you please let me know if this tracking worked for you.

Cheers
Berti