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.
I recently had a client request to add tracking to links created with the Link module. The simplest solution was to add an 'onClick' attribute to the link. While this could be done through jQuery, I need the client to be able to add the GA event tracking code through the UI. Thought?
Comment | File | Size | Author |
---|---|---|---|
#10 | onclick_6.2.x_20111009.patch | 6.37 KB | ptoly |
#9 | link-onclick-1126838-9.patch | 5.71 KB | gastewart |
#3 | 1126838-link-onclick-attribute-3.patch | 2.79 KB | gastewart |
#2 | 1126838-link-onclick-attribute-2.patch | 2.88 KB | jasonsavino |
#1 | 1126838-link-onclick-attribute.patch | 2.81 KB | jasonsavino |
Comments
Comment #1
jasonsavino CreditAttribution: jasonsavino commentedI am adding a patch based on the quick fix I made.
Comment #2
jasonsavino CreditAttribution: jasonsavino commentedneeded to add a conditional statement. Use this patch, ignore the first one.
Comment #3
gastewart CreditAttribution: gastewart commentedDid you, by any chance, edit the patch file by hand to add your conditional statement ?
I applied your original patch cleanly, added the changes you made to your v2 patch, and attached this as a v3 patch.
Cheers,
gavin.
Comment #4
baebs CreditAttribution: baebs commentedawesome, exactly what I needed -- is it correct that only if a new link field is generated within a content type the 'onClick' attribute appears in the Global Settings of the UI -- meaning it doesn't work to add the 'onClick' event to an already existing link field through the UI?
Comment #5
brycesenz CreditAttribution: brycesenz commentedsubscribing. Any chance of this being committed soon?
Comment #6
dqdsadly no. we have priority in catching up all 7 issues to get done the D7 final release soon in the first place. Drupal 5 support is dropped off now but files stay online for any use.
Feel free to provide patches for D6 since we surely will rework them all after D7 release to collect the best for D6 committing.
Comment #7
dqdComment #8
dqdComment #9
gastewart CreditAttribution: gastewart commentedNew patch includes previous patches and provides an optional unfiltered output for onclick, allowing embedded javascript to work as expected. Especially useful for Google Analytics, where you want a URL to look something like:
and not like it was:
Warning: some internal variables were renamed, if you have already been using the onclick patch you may find you need to re-enter your onclick string.
Comment #10
ptoly CreditAttribution: ptoly commentedI put these changes into the latest dev - 6.2x 2011-10-09, and attempted to create a patch. I 'think' I got the patch files path's correct but I'm still new to creating patches...
Comment #11
HongPong CreditAttribution: HongPong commentedWould love to have this available. On a related note for D7 someone else did a hook form alter trick for adding this feature. see https://drupal.org/node/2109265 for their code.
Comment #12
dqdUsually Drupal handles onclick events with actions and rules module. Can anyone confirm that this is not working with link module in D6? Or can anyone report in more detail how this feature request here differs from the usual route we go in Drupal to add actions onclick? Thanks for any details on this.
And please beware that Drupal 6 support is not granted for a too long time after Drupal 8 core release. So we should not put too much energy into this. Unless another user can be persuaded to provide a full patch review for this last patch here before we commit it. Thanks for understanding.
Comment #13
drclaw CreditAttribution: drclaw commentedIf anyone is looking for this for D7, I've created a little module that adds onclick as a "sub" field of the link module. https://www.drupal.org/project/link_onclick
Comment #14
jcfiala CreditAttribution: jcfiala as a volunteer commentedSince drclaw's module fixes this problem, I've added a link to it on the description page, and am closing this issue for now.