concord-consortium/lab — pull request #23 by tdyer (2013-04-02 23:14:19+00:00)
Title: Send model events to google analytics

This addresses a PT Storyfor tracking interactives and models by Google Analytics.
https://www.pivotaltracker.com/projects/731349#!/stories/46994837.

Goto http://lab3.dev.concord.org/interactives#/interactives/interactives_basic-examples_onClick_with_Tracking

Open the interactive editor and view the plotAction -> "adds an atom" onClick handler.
It's action should be:
"action": [
"onClick('plot', function(x, y, d, i) {",
" trackPageContext();",
" trackEvent('', 'Add Atoms', 'Adding Atoms to onClick Demo Interactive');",
" addAtom({x: x, y: y});",
"});"
]

Note the trackPageContext and trackEvent scripting API functions.
The trackPageContext function will send Interactive "Page Context" action/event to Google Analytics with the url of the containing page and the url of the embedded page.

The trackEvent function will send a "Add Atoms" action/event to Google Analytics.

These events can be viewed at https://www.google.com/analytics/web/#realtime/rt-event/a6899787w68675665p70722550/%3Ffilter.list%3D14%3D%3DREFERRAL%3B7%3D%3Dlocalhost%25253A4000%3B/

They are triggered by selecting "adds an atom" radio button and clicking in the model.

To view how this would work in an embedded page go to (this is a page served by development environment, which is not always available):
http://niftytoad.fwd.wf/gaq_lab3_test.html