emencia / emencia-django-newsletter

An app for sending newsletter by email to a contact list.
189 stars 72 forks source link

Being able to avoid tracking on some links #29

Closed alexgarel closed 13 years ago

alexgarel commented 13 years ago

While tracking some links, my client wishes some links not to be tracked (ethical reason or avoiding to much redirects).

Here is a patch which disable tracking of links having the offtrack class.

eg. :

 <a href="http://my.url" class="offtrack">blah<\a>

Won't be tracked.

alexgarel commented 13 years ago
--- a/emencia/django/newsletter/utils/newsletter.py
+++ b/emencia/django/newsletter/utils/newsletter.py
@@ -26,7 +26,8 @@ def track_links(content, context):

     soup = BeautifulSoup(content)
     for link_markup in soup('a'):
-        if link_markup.get('href'):
+        if ( link_markup.get('href') 
+             and  "offtrack" not in link_markup.get('class','').split() ):
             link_href = link_markup['href']
             link_title = link_markup.get('title', link_href)
             link, created = Link.objects.get_or_create(url=link_href,
Fantomas42 commented 13 years ago

Hi alexgarel,

it's a good idea, thank you for the patch, but I have did some changes, I prefer use the rel attribute, than the class attribute.

Fantomas42/emencia-django-newsletter@96145ed4500d9930aa4b1ed301569701e7b0c6c8

alexgarel commented 13 years ago

Yep I did hesitate on using rel but feared it was more standardized and normally specify relation to the target http://en.wikipedia.org/wiki/Link_relation Class seemed to characterised the link itself explaining its rendering. Hence my choice. But nothing strongly rooted :-)