Permalink
Browse files

Add experimental totango support

  • Loading branch information...
1 parent 306f221 commit f7c7da105005e6e8429bc18e13b0123301a8109e @rantav committed Apr 28, 2012
Showing with 103 additions and 5 deletions.
  1. +36 −1 base.html
  2. +9 −4 base_app.html
  3. +58 −0 s/js/jquery-totango-0.1.js
View
@@ -45,6 +45,41 @@
var pageTracker = _gat._getTracker("UA-7467594-1");
pageTracker._trackPageview();
} catch(err) {}</script>
-{% endblock analytics %}
+
+
+<!-- <script src="//s3.amazonaws.com/totango-cdn/sdr.js"></script>
+<script type="text/javascript">
+jQuery(function() {
+ try {
+ var tracker = new __sdr("SP-1918-08");
+ } catch (err) {
+ var tracker = {
+ track: function() {},
+ identify: function() {}
+ }
+ }
+ $('form').instrumentTracking();
+});
+</script>
+ -->
+
+<script src="//s3.amazonaws.com/totango-cdn/totango.js"></script>
+<script type="text/javascript">
+jQuery(function() {
+ try {
+ var totango = new __totango("SP-1918-08");
+ } catch (err) {
+ quite = function () {};
+ var totango = {
+ track: quite,
+ identify: quite,
+ setAccountAttributes: quite
+ };
+ }
+ $('form').instrumentTracking(totango);
+});
+</script>
+
+ {% endblock analytics %}
</body>
</html>
View
@@ -4,8 +4,10 @@
{{css}}
{% endblock page_css %}
{% block page_js %}
+<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript" src="/s/js/app.js?v={{version}}"></script>
+<script type="text/javascript" src="/s/js/jquery-totango-0.1.js" defer></script>
<script type="text/javascript">
{% block js_state_variables %}
var __twg_init_q = '{{q|escape}}';
@@ -25,14 +27,17 @@
{% block content %}
{% block content_heading %}{% endblock %}
{% block inputs %}
-<form onSubmit="{% block on_submit %}twitgraph.Utils.onSubmit();{% endblock %}return false" id="form">
- <div id="search-input">
+<form onSubmit="{% block on_submit %}twitgraph.Utils.onSubmit();{% endblock %}return false" id="form"
+ data-totango-module='twitgraph'
+ data-totango-organization='null corp'
+ data-totango-user='Random TwitGraph User'>
+ <div id="search-input" data-totango-activity='search'>
<input id="q" value="{{q}}" class="text"/>
<input type="submit" id="submit" value="Graph it"/>
</div>
<br class="clear"/>
<div id="search-input-more">
- <div id="divDateStatic" class="{% if dynamic_date %}date-type-lowlight{% else %}date-type-highlight{% endif %}">
+ <div id="divDateStatic" class="{% if dynamic_date %}date-type-lowlight{% else %}date-type-highlight{% endif %}" data-totango-activity='modify date'>
<input type="radio" name="dateDynamic" value="0" id="dateDynamic0" {% if not dynamic_date %} checked="checked" {% endif %} onchange="twitgraph.Utils.highlightDateDynamic(false)"/>
<label for="dateDynamic0">From </label>
<input id="dateStart" class="text" value="{{start}}" size="10"/>
@@ -52,7 +57,7 @@
{% block embed_code %}
<div id="embed">
Embed: <br/>
- <textarea id="embed-code" readonly="readonly" onclick="focus();select()"> </textarea>
+ <textarea id="embed-code" readonly="readonly" onclick="focus();select()" data-totango-activity='embed'> </textarea>
</div>
{% endblock %}
</form>
View
@@ -0,0 +1,58 @@
+(function(window, $, undefined) {
+
+ // Finds the closest definition of the given Totango property;
+ // searches up the DOM tree until it finds an element with the property.
+ // @api private
+ // @param [jQuery node or DOM element] the starting node for the search
+ // @param [String] the Totango property name
+ // @return [String] the value
+ var lookUpTotangoProperty = function(startNode, propertyName) {
+ propertyName = 'data-totango-' + propertyName;
+ return $(startNode)
+ .closest('[' + propertyName + ']')
+ .attr(propertyName);
+ };
+
+ $.fn.extend({
+
+ // Adds Totango tracking to the current element.
+ // If the element is a form, adds an onSubmit handler;
+ // Otherwise, adds an onClick handler.
+ // @param [Totango SDR Tracker] the tracker instance; optional, defaults to window.tracker
+ // @return [jQuery node list] the receiver, as a jQuery node list
+ instrumentTracking: function(tracker) {
+ tracker = tracker || window.tracker;
+ var handler = function() { $(this).trackEvent({ tracker: tracker }); };
+ return $(this)
+ .each(function(i, node) {
+ node = $(node);
+ if (node.is('form')) {
+ node.submit(handler);
+ } else {
+ node.click(handler);
+ }
+ });
+ },
+
+ // Send a tracking event.
+ // @param [Object] overrides, possibly containing "activity", "module",
+ // "organization", "user", and "tracker" properties; optional
+ // @return [jQuery node list] the receiver, as a jQuery node list
+ trackEvent: function(options) {
+ var self = $(this);
+ options = options || {};
+ var tracker = options.tracker || window.tracker;
+ var activity = options.activity || lookUpTotangoProperty(this, 'activity');
+ var module = options.module || lookUpTotangoProperty(this, 'module');
+ var organization = options.organization || lookUpTotangoProperty(this, 'organization');
+ var user = options.user || lookUpTotangoProperty(this, 'user');
+
+ if (tracker && activity && module && organization && user) {
+ tracker.track(activity, module, organization, user);
+ }
+
+ return self;
+ }
+
+ });
+})(window, jQuery);

0 comments on commit f7c7da1

Please sign in to comment.