Last active
November 7, 2015 18:01
-
-
Save chrisblakley/f433b28a741799c4239c to your computer and use it in GitHub Desktop.
Reduce the amount of speculation when making insights in Google Analytics by using context clues to determine the event intent from user interactions. https://gearside.com/event-intent-using-context-clues-determine-user-intention/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery('a.some-link').on('mousedown tap touch', function(e){ | |
eventIntent = ( e.which >= 2 )? 'Intent' : 'Explicit'; | |
ga('set', 'dimension3', eventIntent); | |
ga('send', 'event', 'Category', 'Action', 'Label', 'Value'); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(document).on('cut copy', function(){ | |
var selection = window.getSelection() + ''; | |
var emailPattern = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; | |
var phonePattern = /^(?:(?:\+?1\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})(?:\s*(?:#|x\.?|ext\.?|extension)\s*(\d+))?$/; | |
if ( emailPattern.test(selection) ){ //Mailto link | |
ga('set', 'dimension3', 'Intent'); | |
} else if ( phonePattern.test(selection) ){ //Phone number | |
ga('set', 'dimension3', 'Intent'); | |
} | |
ga('send', 'event', 'Category', 'Action', 'Label', 'Value'); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.matchMedia('print').addListener(function(mq){ //IE9+ | |
if ( !mq.matches ){ | |
ga('set', 'dimension3', 'Intent'); | |
ga('send', 'event', 'Category', 'Action', 'Label', 'Value'); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment