diff --git a/disqus.module b/disqus.module index ac00559..5850e66 100644 --- a/disqus.module +++ b/disqus.module @@ -144,7 +144,7 @@ function disqus_element_post_render($children, &$element) { // Check if we want to track new comments in Google Analytics. if (variable_get('disqus_track_newcomment_ga', FALSE)) { // Add a callback when a new comment is posted. - $disqus['callbacks']['onNewComment'][] = 'disqusTrackNewComment'; + $disqus['callbacks']['onNewComment'][] = 'Drupal.disqus.disqusTrackNewComment'; // Attach the js with the callback implementation. $element['#attached']['js'][] = drupal_get_path('module', 'disqus') . '/js/disqus_ga.js'; } diff --git a/interdiff-1507380-25-28.txt b/interdiff-1507380-25-28.txt new file mode 100644 index 0000000..e69de29 diff --git a/js/disqus_ga.js b/js/disqus_ga.js index 32a1ece..1771397 100644 --- a/js/disqus_ga.js +++ b/js/disqus_ga.js @@ -3,35 +3,36 @@ * JavaScript for the Disqus Google Analytics module. */ -(function($) { +(function ($) { - /** - * Track new comments in Google analytics. - * Custom modules can override this by implementing hook_js_alter(). - */ - disqusTrackNewComment = function() { +Drupal.disqus = {}; - // Make sure that the google analytics event tracking object or - // the universal analytics tracking function exists - // if not then exit and don't track. - if (typeof _gaq == "undefined" && typeof ga == "undefined") { - return; - } +/** + * Track new comments in Google analytics. + * Custom modules can override this by implementing hook_js_alter(). + */ + Drupal.disqus.disqusTrackNewComment = function () { + // Make sure that the google analytics event tracking object or + // the universal analytics tracking function exists + // if not then exit and don't track. + if (typeof _gaq == "undefined" && typeof ga == "undefined") { + return; + } - // Construct current page relative URL to be used as event Label. - var label = document.location.href.toLowerCase().substring((document.location.href.toLowerCase().indexOf(document.domain.toLowerCase())) + (document.domain.toLowerCase().length)); + // Construct current page relative URL to be used as event Label. + var label = document.location.href.toLowerCase().substring((document.location.href.toLowerCase().indexOf(document.domain.toLowerCase())) + (document.domain.toLowerCase().length)); - if (typeof _gaq != 'undefined') { - _gaq.push(['_trackEvent', 'Disqus', 'Comment', label]); - } - else { - ga('send', { - 'hitType': 'event', - 'eventCategory': 'Disqus', - 'eventAction': 'Comment', - 'eventLabel': label - }); - } - }; + if (typeof _gaq != 'undefined') { + _gaq.push(['_trackEvent', 'Disqus', 'Comment', label]); + } + else { + ga('send', { + 'hitType': 'event', + 'eventCategory': 'Disqus', + 'eventAction': 'Comment', + 'eventLabel': label + }); + } + }; -})(jQuery); \ No newline at end of file +})(jQuery);