Author image Gligan Calin Horea


WWW::ClickSource - Determine the source of a visit on your website : organic, adwords, facebook, referer site


Version 1.0002


Help determine the source of the traffic on your website.

This module tries to do what GoogleAnalytics, Piwik and other monitoring tools do, but it's something you can use on the backend of your application in real time.

This module can be used together with HTTP::BrowserDetect to get an even deeper understanding of where your traffic is generated from.


Can be used in one of two ways

OOP interface :

    use WWW::ClickSource;
    my $click_source = WWW::ClickSource->new($request);

    my $source = $click_source->source();
    my $medium = $click_source->medium();
    my $campaign = $click_source->campaign();
    my $category = $click_source->category();

or using Export

    use WWW::ClickSource qw/detect_click_source/;

    my %click_info = detect_click_source($request);

The $request argument is one of Catalyst::Request object or a hash ref with the fallowing structure:

        host => '',
        params => {
            param_1 => 'value_1',
            param_n => 'value_n',
        referer => ''

params contains the query params from the current HTTP request.


Here is an example on how you can use this module, to keep track of where the user came from using your session object

In case we have a new session but the request had another page on your website as a referer (category is 'pageview') we actually want to tag the current page view as being direct traffic. You have to do this yourself because WWW::ClickSource doesn't know the status of your session.

    my $click_source = WWW::ClickSource->new($request);
    if (! $session->click_source ) {
        if ($click_source->category ne "pageview") {
        else {
            $session->click_source({category => 'direct'});
    elsif ($click_source->category ne "pageview") {



Creates a new WWW::ClickSource object


Determine where the user came from based on a request object


Source of the click picked up from utm_source request param or referer domain name

Only available in OOP mode


Medium from which the click originated, usually picked up from utm_medium request param

Only available in OOP mode


Click category, can be one of : direct, paid, referer, pageview

'pageview' means the user came accessed the current page by clicking on a link on another page of the same website. (referer host is the same as your domain name)

Only available in OOP mode


Campaign from which the click originated, usually picked up from utm_campaign request param

Only available in OOP mode


Return a hash containing all the relevant attributes of the current object

Only available in OOP mode


Instance of WWW::ClickSource::Request or a subclass of it, representing the internal request object used to extract the info we need

Only available in OOP mode and if you specify that you want access to the request object using keep_request => 1

    my $click_source = WWW::ClickSource->new($request, keep_request => 1);


Gligan Calin Horea, <gliganh at>



Please report any bugs or feature requests to bug-www-session at, or through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


You can find documentation for this module with the perldoc command.

    perldoc WWW::ClickSource

You can also look for information at:


Copyright 2016 Gligan Calin Horea.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See for more information.