Git Product home page Git Product logo

nrsutton-visitor-tracker's Introduction

Visitor Tracker

Visitor tracker allows you to attach the visitors path through your website to any contact form submission.

To use, install Visitor Tracker by placing the files in a directory of your choosing in the root of your SilverStripe project.

Then in the method that submits your form data, add the code

$email = new Email(
    'email_from',
    'email_to',
    'email_subject'
);

$email->setTemplate( 'YourEmailTemplate' );

$data = $this->getData();
$data[ "Visitor" ] = Visitor::initVisitor();

$email->populateTemplate( $data );

This gives you access to the visitor objects fields which in turn give you access to the array of pageView objects

Below is a demonstration of an email template

<html>
	<body>
		<p><font face="arial" size="2">An enquiry has been received with the following details:</font></p>
	    <ul>
		    <li><font face="arial" size="2"><strong>Name:</strong> $Name</font></li>
		    <li><font face="arial" size="2"><strong>Contact Information:</strong> $ContactInfo</font></li>
		    <li><font face="arial" size="2"><strong>Enquiry:</strong> $Enquiry</font></li>
		</ul>

	    <% if $Visitor %>
	    	<br/><hr width="75%">
		    <h2 margin="0"><font face="arial" size="3">Site usage details</font></h2>
		    <p><font face="arial" size="2">
				Below are the details of this users path through the site
			</font></p>
	    
	    <% if $Visitor.referer %>
	    	<p><font face="arial" size="2"><strong>Referal URL:</strong> $Visitor.referer</p>
	    <% end_if %>

	    <table border=1>
	    	<tr>
	    		<th>
	    			<font face="arial" size="2">URL</font>
	    		</th>
	    		<th>
	    			<font face="arial" size="2">Scroll depth</font>
	    		</th>
	    		<th>
	    			<font face="arial" size="2">Time on page (Seconds)</font>
	    		</th>
	    	</tr>
	    
		    <% loop $Visitor.PageViews %>
		    <tr>
			    <td>
			    	<font face="arial" size="2">$URL</font>
			    </td>
			    <td>
			    	<font face="arial" size="2">
			    	<% if Last %>
			    		No data
			    	<% else %>
			    		$ScrollDepth%
			    	<% end_if %>
			    </font>
			    </td>
			    <td>
			    	<font face="arial" size="2">
			    	<% if Last %>
				    	No data
			    	<% else %>
			    		$TimeOnPage
			    	<% end_if %>
			    	</font>
			    </td>
		    </tr>
		    <% end_loop %>
	    </table>
	    <% end_if %>
    </body>
</html>

Note that the last page visited in the list, will not have a scroll depth or time on page.

nrsutton-visitor-tracker's People

Contributors

nrsutton avatar

Watchers

James Cloos avatar helpfulrobot avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.