An open API service indexing awesome lists of open source software.

https://github.com/flipboxfactory/craft-tracker


https://github.com/flipboxfactory/craft-tracker

Last synced: 8 months ago
JSON representation

Awesome Lists containing this project

README

          

# Tracker Integration Plugin for Craft CMS
[![Join the chat at https://gitter.im/flipboxfactory/craft-tracker](https://badges.gitter.im/flipboxfactory/organizations.svg)](https://gitter.im/flipboxfactory/organizations?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Latest Version](https://img.shields.io/github/release/flipboxfactory/craft-tracker.svg?style=flat-square)](https://github.com/flipboxfactory/craft-tracker/releases)
[![Software License](https://img.shields.io/badge/license-Proprietary-brightgreen.svg?style=flat-square)](LICENSE.md)
[![Build Status](https://img.shields.io/travis/flipboxfactory/craft-tracker/master.svg?style=flat-square)](https://travis-ci.org/flipboxfactory/craft-tracker)
[![Coverage Status](https://img.shields.io/scrutinizer/coverage/g/flipboxfactory/craft-tracker.svg?style=flat-square)](https://scrutinizer-ci.com/g/flipboxfactory/craft-tracker/code-structure)
[![Quality Score](https://img.shields.io/scrutinizer/g/flipboxfactory/craft-tracker.svg?style=flat-square)](https://scrutinizer-ci.com/g/flipboxfactory/craft-tracker)
[![Total Downloads](https://img.shields.io/packagist/dt/flipboxfactory/craft-tracker.svg?style=flat-square)](https://packagist.org/packages/flipboxfactory/craft-tracker)

## Installation

To install, use composer:

```
composer require flipboxfactory/craft-tracker
```

## Testing

``` bash
$ ./vendor/bin/phpunit
```

## Contributing

Please see [CONTRIBUTING](https://github.com/flipboxfactory/craft-tracker/blob/master/CONTRIBUTING.md) for details.

## Credits

- [Flipbox Digital](https://github.com/flipboxfactory)

## License

Please see [License File](https://github.com/flipboxfactory/craft-tracker/blob/master/LICENSE) for more information.

## Examples

#### List Event Counts via RollUp object
```twig


    {% for rollUp in craft.tracker.rollUp.author(currentUser).all()
    %}

  • {{ rollUp.entry.title }}


    Hit Count: {{ rollUp.count }}

  • {% endfor %}

```

#### List All Events By Entry
```twig
{% set entryId = 1 %}


    {% for event in craft.tracker.query.entryId(entryId).all() %}

  • {{ event.title }} -- {{ event.event }}


    User Agent: {{ event.userAgent }}

    IP: {{ event.remoteIp }}

    OS: {{ event.clientOs }}

    Created At: {{ event.dateCreated }}

    Metadata:

      {% for key, value in event.metadata|json_decode %}

    • {{ key }} - {{ value }}

    • {% endfor %}


  • {% endfor %}

```

#### Record Event via TWIG Template
```twig

{# Basic 'Page View' type tracking #}
{% do craft.tracker.track({entry: entry}) %}

{# Explicitly set track attributes #}
{% do craft.tracker.track({entry: entry, event: "Viewed::PDF"}) %}
```

#### Record Event (AJAX / JQuery)
```twig

{% set metadata = {foo: "bar"} %}

Goto Google

$(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);
},
});
});
});

```