Author image Gligan Calin Horea

NAME

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

VERSION

Version 1.0002

DESCRIPTION

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.

SYNOPSIS

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 => 'mydomain.com',
        params => {
            param_1 => 'value_1',
            ...
            param_n => 'value_n',
        },
        referer => 'http://referer-website.com/some_link.html?param1=value1'
    }

params contains the query params from the current HTTP request.

EXAMPLE

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") {
            $session->click_source($click_source->to_hash);
        }
        else {
            $session->click_source({category => 'direct'});
        }
    }
    elsif ($click_source->category ne "pageview") {
        $session->click_source($click_source->to_hash);
    }

METHODS

new

Creates a new WWW::ClickSource object

detect_click_source

Determine where the user came from based on a request object

source

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

Only available in OOP mode

medium

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

Only available in OOP mode

category

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

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

Only available in OOP mode

to_hash

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

Only available in OOP mode

request

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);

AUTHOR

Gligan Calin Horea, <gliganh at gmail.com>

REPOSITORY

https://github.com/gliganh/WWW-ClickSource

BUGS

Please report any bugs or feature requests to bug-www-session at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WWW-ClickSource. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

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

    perldoc WWW::ClickSource

You can also look for information at:

LICENSE AND COPYRIGHT

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 http://dev.perl.org/licenses/ for more information.