Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi there,
I would like to track my disqus commenting with google analytics, was wondering if by any chance it was on the list of things to add? I assume it could be quite straight forward: perhaps a checkbox to activate it and a text field/ textarea with the script command you want to trigger upon commenting?
In the meantime, which part can I include the required line at so that it works?
The line to include is:
function disqus_config() {
this.callbacks.onNewComment = [function() { /* call tracking command here */ }];
}
as specified on http://docs.disqus.com/help/60/
Thanks!
Comment | File | Size | Author |
---|---|---|---|
#29 | disqus-ga-integration-1507380-28.patch | 14.83 KB | hugronaphor |
#29 | interdiff-1507380-25-28.txt | 3.12 KB | hugronaphor |
#22 | disqus-ga-integration-1507380-22-8.x-1.x.patch | 5.67 KB | hugronaphor |
#3 | disqus-ga-integration-1507380-3.patch | 2.92 KB | girishmuraly |
#11 | disqus-ga-integration-1507380-11.patch | 14.83 KB | hugronaphor |
Comments
Comment #1
telegraph CreditAttribution: telegraph commentedComment #2
awolfey CreditAttribution: awolfey commentedI think the question here is also how to use drupal_add_js() to add the callback.
something like that should work, right?
Comment #3
girishmuraly CreditAttribution: girishmuraly commentedI have the same request and I think the best approach would be to implement the callback in a #post_render to the 'disqus' element. I've attached a patch that does this in a module called disqus_ga which I'm hoping can be a submodule to Disqus.
Other modules that want to do something different on the callback can either override the js callback using hook_js_alter() or follow the logic of the module to add their own callback.
Comment #4
slashrsm CreditAttribution: slashrsm commentedYour patch looks like a whole new module. Did you want to include it in Disqus integration or create a standalone plugin?
Comment #5
girishmuraly CreditAttribution: girishmuraly commentedI thought it would benefit everybody if it was a submodule of Disqus. What do you think?
Comment #6
slashrsm CreditAttribution: slashrsm commentedThat would work, but we need a patch against module for that also.
Comment #7
girishmuraly CreditAttribution: girishmuraly commentedI thought this patch would work. Works for me. Is there something I need to follow? Could you point me in the right direction please? Thank you.
Comment #8
hugronaphor CreditAttribution: hugronaphor commentedHere is the patch which is going to integrate the GA Tracking without creating a sub-mudule as in my opinion having a separate module for that is superfluous.
Things to mention:
- This patch will support the both, the old GA api and the new analytics.js and Universal Analytics (see: https://developers.google.com/analytics/devguides/collection/upgrade/ref... ).
Inspired from http://cgit.drupalcode.org/google_analytics_et/tree/js/google_analytics_... ;
- As we have already 3 .js files it's worth to move theme in a separate directory "js";
Please review.
Comment #9
slashrsm CreditAttribution: slashrsm commentedThank you for your work. Looks very good. I'd suggest just few simple cosmetic improvements:
Let's add this new configuration variable to the hook_uninstall().
Missing newline.
It would be great to get this into 8.x-1.x first.
Comment #10
hugronaphor CreditAttribution: hugronaphor commentedThanks for the improvements suggestion.
Attaching the improved patch for 7.x-1.x (I also changed the callback name to make it more descriptive).
In the main time I'll work on 8.x-1.x branch.
Comment #11
hugronaphor CreditAttribution: hugronaphor commentedI saw that variable deletion is sorted alphabetically - pushing new variable in the corespondent place :)
Comment #12
hugronaphor CreditAttribution: hugronaphor commentedHere is the patch for 8.x-1.x
Comment #13
hugronaphor CreditAttribution: hugronaphor commentedComment #14
slashrsm CreditAttribution: slashrsm commentedJS file seems to be missing in D8 patch.
Comment #15
slashrsm CreditAttribution: slashrsm commented@hugronaphor: Check https://www.drupal.org/documentation/git/interdiff. Interdiffs are great way to clearly show changes between individual patches and make it much easier for people to review your work.
Comment #16
hugronaphor CreditAttribution: hugronaphor commentedHere is the fixed patch with js file included and interdiff.
Thanks for pointing me into the right direction.
Comment #17
slashrsm CreditAttribution: slashrsm commentedThanks! This looks great. I missed another critical and another cosmetic thing during my last review. I apologize for ping-pong....
Library name is actually "disqus/disqus". However, since GA integraton can be disabled it would be nicer to separate it's JS into a separate library (which could be called "disqus/ga" eventually).
See https://www.drupal.org/node/2201089 for more info about libraries and their definition.
Would be nice to have this function namespaced in "Drupal.disqus". This applies to D7 too.
Comment #18
hugronaphor CreditAttribution: hugronaphor commentedBefore uploading the patch, would this be the correct way? :
disqus.libraries.yml
And I'm not sure I understand the meaning of "Drupal.disqus" namespace.
Do you mean as Drupal behavior maybe:
?
Comment #19
slashrsm CreditAttribution: slashrsm commentedComment #20
hugronaphor CreditAttribution: hugronaphor as a volunteer commentedThis Issue can't be solved until the https://www.drupal.org/node/2476065 is not merged into 8.x-1.x
Comment #21
slashrsm CreditAttribution: slashrsm commented#2476065 was merged.
Comment #22
hugronaphor CreditAttribution: hugronaphor as a volunteer commentedThanks @slashrsm
Here is the latest patch against 8.x-1.x
Comment #24
slashrsm CreditAttribution: slashrsm as a volunteer commentedCommitted. Thank you!
Now we can include this in D7 version too.
Comment #25
hugronaphor CreditAttribution: hugronaphor as a volunteer and at Dennis for Dennis commentedHere is the last path against the 7.x-1.x
Even if you suggested to namespace the function
disqusTrackNewComment
in "Drupal.disqus" namespace - I found it a bit difficult to manage the order of added JS files as we did in D8 branch (by using the libraries "dependenctcies" property) and this may create problems in future.Comment #26
slashrsm CreditAttribution: slashrsm as a volunteer commentedThere are no other JS functions using this namespace at the moment so this would not be a problem, right?
Comment #27
hugronaphor CreditAttribution: hugronaphor as a volunteer and at Dennis for Dennis commentedCorrect, there are no other JS functions using this namespace.
I'm concerned about where to declare the
Drupal.disqus = {};
to make sure this will be available in any other part of APP. But you never can be sure without checking if the object exist already (this what I'm trying to avoid).Comment #28
slashrsm CreditAttribution: slashrsm as a volunteer commentedFor now we could declare it in this file and try to fix this problem when we face it.
Comment #29
hugronaphor CreditAttribution: hugronaphor as a volunteer and at Dennis for Dennis commentedI see what you mean. Here it is.
Comment #30
slashrsm CreditAttribution: slashrsm at Examiner.com commentedCommitted. Thanks!