Adding an output buffer callback

View: New views
5 Messages — Rating Filter:   Alert me  

Adding an output buffer callback

by William Canino :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

One of the features of Google Analytics and GA plugins is the ability
to track outgoing links using this technique
http://www.google.com/support/googleanalytics/bin/answer.py?hl=en&answer=55527
.

I reviewed the various GA plugins and saw that they only run their
preg_match_replace inside a filter hook on the_content, the_excerpt
and comment_text.  This means they don't track outbound links on the
theme, the widgets, and the output of plugins.

Another thing they don't track is where people click the blog's feeds
link and how often.

I want to improve this by preg_match_replace-ing the whole page
output.  I have written a function ga_link() that modifies hyperlinks
to insert this tracking code.

I would like advice on where to best call ob_start('ga_link') and
ob_end_flush().

W
_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: Adding an output buffer callback

by Eric Marden-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Nov 1, 2009, at 11:41 PM, William Canino wrote:
> I want to improve this by preg_match_replace-ing the whole page
> output.  I have written a function ga_link() that modifies hyperlinks
> to insert this tracking code.
>
> I would like advice on where to best call ob_start('ga_link') and
> ob_end_flush().


You might want to do that on wp_head and wp_footer actions.

That way you pretty much get everything between the body tags, which  
is all you care about anyway.

More:
http://codex.wordpress.org/Plugin_API/Action_Reference/wp_head
http://codex.wordpress.org/Plugin_API/Action_Reference/wp_footer

Though this seems like an awful lot of processing just to tag outbound  
links. Some of the ones you mentioned might be best served being done  
in the theme layer or hard coded.


- Eric Marden
__________________________________
http://xentek.net/code/wordpress/





_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: Adding an output buffer callback

by Andrew Nacin :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

>
> I want to improve this by preg_match_replace-ing the whole page output.
>

The solution to your problem isn't using output buffering to generate a lot
of obtrusive JavaScript. Have you considered unobtrusive JavaScript? That
would rather clearly make the most sense here.
_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: Adding an output buffer callback

by William Canino :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Andrew, that is a tough question because I'm afraid my ga_link() is
all ready in PHP.

Is unobtrusive Javascript better, across the board?

W

2009/11/2 Andrew Nacin <anacin@...>:

>>
>> I want to improve this by preg_match_replace-ing the whole page output.
>>
>
> The solution to your problem isn't using output buffering to generate a lot
> of obtrusive JavaScript. Have you considered unobtrusive JavaScript? That
> would rather clearly make the most sense here.
> _______________________________________________
> wp-hackers mailing list
> wp-hackers@...
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: Adding an output buffer callback

by Eric Marden-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> Is unobtrusive Javascript better, across the board?

Yes. But has its draw backs, especially when crawling the entire DOM  
for links or the fact (performance) or that it won't work for non-JS  
using folks (obviously).

Let a plugin handle the links in the post/page content, and hand tag  
the rest, I say.




- Eric Marden
__________________________________
http://xentek.net/code/wordpress/





_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers