Closed (fixed)
Project:
Google Analytics
Version:
8.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
6 Nov 2012 at 17:48 UTC
Updated:
8 Jul 2021 at 20:19 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
hass commentedThis looks not functional in Drupal. :-(
I cannot find any link in my D7 that has an
IDdefined nor any useful element with an ID 3 levels up. Without an ID defined the feature is pointless and does not work at all. This is a no-brainer feature to me as it is not common to add an ID to a link. We have been encouraged over years to use css classes only and leave the IDs behind in every element for flexibility reasons.Comment #2
plazik commentedI think it doesn't depend on Drupal.
If you want to use this feature you can add ID to your link.
Comment #3
hass commentedHow?
Comment #4
plazik commentedFor example: in theme, with Menu attributes module, in a text editor etc.
Comment #5
jlea9378 commentedSo how can we add the code to enable this feature?
Comment #6
owen barton commentedFrom my reading of the docs it only needs "an element" with an ID within 3 levels of DOM parent levels of the clicked element, which (unlike "A" tag IDs) I think is quite often to be the found on typical Drupal sites/links, for example blocks, nodes, views often include div IDs etc.
The example at https://support.google.com/analytics/bin/answer.py?hl=en&utm_id=ad&answe... uses an "a" tag as the example, but the text says "Checks the ID of the click-target element, and if not found, climbs the DOM up to 3 levels to find an element with an ID;" - this makes sense to me, since part of the purpose of this is to track "clickable things" other than just "a" tags.
Reopening to take another look at this.
Comment #7
hass commentedWe can add it, but I still only have IDs on node forms. This is in my case 5-6 levels or more away from my links. This may be theme related partly, but by default this feature need to be disabled and we need to add a clear message that IDs are not very common.
Comment #8
plazik commentedBlocks have IDs by default.
I think it will be useful if someone wants to track information only for some links but not for all. For example it might be Sign up button in header and button before comments. In this case theme developer should adds IDs by hands.
Comment #9
wiifmHere is an initial patch for 7.x-1.x to support this new functionality. Would be keen for a few people to test this, and see a) if it works, b) does it break anything.
I believe this option should be disabled by default, as it does require a user to manually change something in their GA profile in order to see the statistics. This should maybe be in the description of the checkbox.
Comment #10
owen barton commentedAdded a description to the form noting that the feature needs to be enabled in GA. Didn't test actual tracking though.
I also added a preprocess function which will add sequential numeric IDs to all links, but it occurred to me that is probably a bad approach, since the IDs will change over time and GA may start tracking different links are the same. Rather, if we do add an ID I think it would need to incorporate the "right amount" of context in the ID, which I think is a hard problem. My suggestion would be to leave out this chunk and we can see how this performs using block/node IDs.
Comment #11
owen barton commentedComment #12
hass commentedWe are never using l() in translatable strings.
Comment #13
kscheirerI think this feature is definitely worth adding. @hass your site may not easily make use of this feature, but that doesn't mean someone else's Drupal site can't.
in D7 you don't need to provide a default for variable gets anymore, the default will be NULL.
then you can simplify this to just if (variable_get('googleanalytics_tracklinkid')) { ...
I don't like this approach at all.
Lets leave the site's html alone, enabling this feature does not require this. If you notice your additional link information is not sufficient, we can put this in an example in README.TXT or something.
But we shouldn't assume this much about your site's html.
Comment #14
duntuk commentedDoes this do the following?:
Track which specific links are clicked on which specific page.
I'm asking because this seems like a basic link tracking need.
For instance, say you have the same 'buy now' button on every page. If you have multiple products, you would want to know from what page that 'buy now' button was clicked from.
Comment #15
kscheirerThese patches implement google analytics' enhanced link tracking - which does what you're asking. So yes!
Comment #16
duntuk commentedCool! Thanks kscheirer.
Comment #17
Anonymous (not verified) commentedThis feature would be very welcome. I see no good reason not to at least include it as an option. I've already got our theme adding unique IDs to links or their immediate parents (at least to the ones we want to track, which are mostly menu links so it was incredibly easy). I just need the analytics code to be right now. If I can't get that through the module, I'll just have to strip the module out of our system and include the analytics code myself in the theme.
Comment #18
hass commentedI'm also not sure if I like the hook_preprocess_link() and removed it therefore. I think we can commit this for now.
Comment #19
hass commentedMinor changes in capitalization.
Comment #20
hass commentedBefore committing this I'd like to optimize the setting description. We should explain what this checkbox does and not just telling people they need to enable it in their Google Accounts. This is not useful to understand what they get.
Please make a suggestion.
Comment #21
kscheirerPerhaps add a link to google's docs on what the ELA feature does?
The patch is rtbc from me - again you don't need to give a 2nd parameter when doing a variable_get() anymore, but that's a pretty minor quibble.
Comment #22
hass commentedAs said, I'm fine with committing this once the "description" really explains what the checkbox does. The current text don't help inexperienced users.
Comment #23
hass commentedThere seems no upgrade path to Universal Analytics or has someone an idea how it looks like?
Comment #24
soundstripe commentedI edited the description. Didn't test the patch, but as comment 22 said he was fine with committing with a better description. This good enough?
Comment #26
kevishie commentedFixed patch from #24
Comment #27
loparr commentedIs there same patch for drupal 6? thank you
edit
Now, I am not sure if that is a good way but I simply took the needed code and put it inside the googleanalytics.module like so
$script = 'var _gaq = _gaq || [];';
$script .= 'var pluginUrl = "//www.google-analytics.com/plugins/ga/inpage_linkid.js";';
$script .= '_gaq.push(["_require", "inpage_linkid", pluginUrl]);';
The last two lines are needed according google tutrial https://support.google.com/analytics/answer/2558867?hl=en&utm_id=ad
After clearing cache, the code looks ok, no script errors on page. GA works as usual but Inpage analytics, where this code should take an effect won't start. I get a message - problem loading. We could not find what is wrong with your setup. Please ty later. What could be wrong?
Comment #28
jlea9378 commentedSeems to work fine. I patched 7.x-1.4 with patch in #26. No errors or anything.
Can we mark this RTBC and get it committed?
Comment #29
neochief commentedHere's the same changes for 2.x branch (using new analytics code).
Comment #30
neochief commentedOops, missed the changes in install file. Here's the correct patch for 7.x-2.x branch.
Comment #33
hass commentedComment #34
hass commented30: enchanced-link-attribution-7.x-2.x-1833578.patch queued for re-testing.
Comment #35
hyperglide commented30: enchanced-link-attribution-7.x-2.x-1833578.patch queued for re-testing.
Comment #36
hyperglide commentedHas anyone had any luck testing this?
Comment #40
hass commentedThanks to all who helped getting this done.
I committed it to all 7 and 8 branches. No backport to 6.x has been done as it is near end of life. If you need this upgrade Drupal Core, please.
Comment #41
hass commented