In the post Notice a copy event on your blog by email only by JavaScript, the copy events are sent to Mandrill to make an email notice.
In this post, I would introduce how to analyze such events in Google Analytics.
JavaScript Code
Here is a snippet to send a copy event to Google Analytics:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
|
Place this code in your <head>...</head>
as above.
In this code, it assumes Universal Analytics version (analytics.js).
The key point is usage of Analytics’ event tracking:
ga('send', 'event', 'copy', location.href + ':' + document.title, selected);
In this function, arguments mean:
- 1st arg: Command.
send
to send information to Google Analytics. - 2nd arg: hitType.
event
to set Event Tracking. - 3rd arg: eventCategory. Category of the event (<150bytes).
- 4th arg: eventAction. Action of the event (<150bytes).
- 5th arg: eventLabel. Label of the event (<150bytes).
- 6th arg: eventValue. Value of the event (>=0). It is omitted in this time.
If you are using old version (ga.js), replace:
ga('send', 'event', 'copy', location.href + ':' + document.title, selected);
with
_gaq.push(['_trackEvent', 'copy', location.href + ':' + document.title, selected]);
Check copy events in Google Analytics
You can find the results in BehaviorEvents.
In Overview, copy category is there.
Choose copy and click Event Action, there is a page list.
If go to Event Label, you can find what were copied in your blog. If you choose any page in Event Action first, then go to Event Label, only copies of the selected page are shown.
In above snippet, copied region is sent as HTML. Therefore, if the large region is copied, you will see sentences with HTML tags.
If you wish to have only text, manage select
variable in above snippet like:
1 2 |
|
and
1 2 |
|
At Event Category page, you can use Secondary dimension to divide events into each page or title, too.
If you want to add more marks to divide into, you can use Event Action instead of the page url+title.