@kevinoid opened this Issue on March 19th 2015

Hello Piwik Developers,

I am using Piwik on a website with a frontend written in AngularJS and finding it very difficult to do link tracking with Piwik. The source of the difficulty is that enableLinkTracking only tracks links which exist and have an href property at the moment Piwik is initialized, which can be before or after Angular initialization, depending on script load timing. Although this can be combined or replaced with addListener on individual link elements, the lack of ability to query which elements are currently tracked and the dynamic nature of frameworks like Angular which often create and destroy elements can make this quite difficult and cumbersome.

I am curious if you have considered replacing the per-link event listener with a single event listener on the html element which can listen for click events as they bubble. This way all links, dynamic and static, could be tracked without additional work by the user. There would be a performance cost, since each click event would cause DOM traversal to check if the click was on an a or area element, but the cost seems reasonable for most uses. Alternatively, this could be avoided by creating a enableDynamicLinkTracking method to require users to opt-in to this behavior.

What do you think? If this approach seems reasonable, I'd be happy to send a PR. If not, perhaps alternative approaches for improved support of dynamic link tracking could be considered?

Thanks for your time and consideration,
Kevin

@mattab commented on March 19th 2015 Owner

Hi @kevinoid

This sounds interesting, especially if you propose the working pull request :+1:

Regarding speed: I guess listening to all clicks is costly, in case user clicks a lot like in some games, or when the DOM tree is huge and it's costly to know where we've clicked. we could put "safe nets" to skip some clicks if clickrate is high...

Maybe others will have some feedback as well!

@kevinoid commented on March 19th 2015

Hi @mattab

Thanks for the encouragement, I'll give it a shot.

Would you prefer the initial PR to apply the new behavior to the existing enableLinkTracking method (with or without the "safe nets" you mentioned), or should I create a new method such as enableDynamicLinkTracking? Obviously it can be changed later, just want to start as close as possible to the goal.

@mattab commented on March 19th 2015 Owner

good to hear.

you can create enableDynamicLinkTracking and then we can easily call it from enableLinkTracking or not

@mattab commented on April 8th 2015 Owner

we'll be very happy to review your pull request if/when you create one :+1:

@kevinoid commented on April 8th 2015

Hey @mattab, thanks for the ping. Sorry about the delay, I had some unexpected priority changes on my current project which set me back a bit. I'm planning to have the first-draft PR ready in the next day or two, but if I don't, feel free to ping me again. It's still a priority for me!

@tomalex0 commented on November 13th 2016

Curios to know if this feature is available now? @mattab @kevinoid

@kevinoid commented on November 13th 2016

Good question @tomalex0. I left the project which needed this feature shortly after my last comment and I never got around to sending the PR. I'm not aware of any other work on the issue. I'll look around to see if I still have the prototype code I was working on and if it might still be useful.

@mattab commented on November 21st 2016 Owner

@kevinoid as the issue is still opened we haven't implemented it yet. It would be great if you can create a pull request for this improvement :+1:

@tomalex0 commented on December 13th 2016

@mattab , i'm using piwik in angular2 application, and i'm going to write a directive to address this issue for the mean time.

would like to know how you differentiate outlinks and download and how application urls are excluded from the outlinks and download

Powered by GitHub Issue Mirror