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?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jasonsavino’s picture

I am adding a patch based on the quick fix I made.

jasonsavino’s picture

Assigned: Unassigned » jasonsavino
FileSize
2.88 KB

needed to add a conditional statement. Use this patch, ignore the first one.

gastewart’s picture

patch -p1 < ../1126838-link-onclick-attribute-2.patch
patching file link.module
patch: **** malformed patch at line 78:  

Did 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.

baebs’s picture

awesome, 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?

brycesenz’s picture

subscribing. Any chance of this being committed soon?

dqd’s picture

sadly 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.

dqd’s picture

Priority: Normal » Minor
dqd’s picture

Assigned: jasonsavino » Unassigned
gastewart’s picture

New 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:

<a href="http://some.domain" onclick="_gaq.push(['_link', 'http://some.domain']); return false;">Some link</a>

and not like it was:

<a href="http://some.domain" onclick="_gaq.push([&#039;_link&#039;, &#039;http://some.domain&#039;]); return false;">Some link</a>

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.

ptoly’s picture

I 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...

HongPong’s picture

Issue summary: View changes

Would 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.

dqd’s picture

Status: Active » Postponed (maintainer needs more info)

Usually 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.

drclaw’s picture

If 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

jcfiala’s picture

Status: Postponed (maintainer needs more info) » Closed (won't fix)

Since drclaw's module fixes this problem, I've added a link to it on the description page, and am closing this issue for now.