To install, use composer:
composer require flipboxfactory/craft-tracker
$ ./vendor/bin/phpunit
Please see CONTRIBUTING for details.
Please see License File for more information.
<ul>
{% for rollUp in craft.tracker.rollUp.author(currentUser).all()
%}
<li>
<h3>{{ rollUp.entry.title }}</h3>
Hit Count: {{ rollUp.count }}
</li>
{% endfor %}
</ul>
{% set entryId = 1 %}
<ul>
{% for event in craft.tracker.query.entryId(entryId).all() %}
<li>
<h3>{{ event.title }} -- {{ event.event }}</h3>
<strong>User Agent:</strong> {{ event.userAgent }} <br />
<strong>IP:</strong> {{ event.remoteIp }} <br />
<strong>OS:</strong> {{ event.clientOs }} <br />
<string>Created At:</string> {{ event.dateCreated }} <br />
<strong>Metadata:</strong>
<ul>
{% for key, value in event.metadata|json_decode %}
<li>
<strong>{{ key }}</strong> - {{ value }}
</li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
{# Basic 'Page View' type tracking #}
{% do craft.tracker.track({entry: entry}) %}
{# Explicitly set track attributes #}
{% do craft.tracker.track({entry: entry, event: "Viewed::PDF"}) %}
{% set metadata = {foo: "bar"} %}
<a href="https://google.com"
data-event="Click::LinkToGoogle"
data-entry-id="131"
data-element-id="125"
data-metadata="{{ metadata|json_encode() }}"
data-title="Lorem ipsum dolor sit amet, consectetur adipiscing elit">Goto Google</a>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"
integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
<script>
$(function () {
$('[data-event][data-entry-id]').click(function () {
let data = $(this).data();
data.{{ craft.app.config.general.csrfTokenName }} = "{{ craft.app.request.csrfToken }}"
console.log("Begin track event", data);
$.ajax({
async: false,
type: "POST",
url: "{{ actionUrl('/tracker/track/event') }}",
data: JSON.stringify(data),
headers: {
Accept: "application/json; charset=utf-8",
"Content-Type": "application/json; charset=utf-8"
},
contentType: "application/json",
dataType: "json",
success: function (response) {
console.log("End track event", response);
},
});
});
});
</script>