https://github.com/flipboxfactory/craft-tracker
https://github.com/flipboxfactory/craft-tracker
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/flipboxfactory/craft-tracker
- Owner: flipboxfactory
- License: other
- Created: 2021-01-27T15:46:53.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-03-04T16:22:08.000Z (over 5 years ago)
- Last Synced: 2025-01-03T15:25:56.583Z (over 1 year ago)
- Language: PHP
- Size: 24.4 KB
- Stars: 0
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Tracker Integration Plugin for Craft CMS
[](https://gitter.im/flipboxfactory/organizations?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[](https://github.com/flipboxfactory/craft-tracker/releases)
[](LICENSE.md)
[](https://travis-ci.org/flipboxfactory/craft-tracker)
[](https://scrutinizer-ci.com/g/flipboxfactory/craft-tracker/code-structure)
[](https://scrutinizer-ci.com/g/flipboxfactory/craft-tracker)
[](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
-
{{ rollUp.entry.title }}
Hit Count: {{ rollUp.count }}
{% for rollUp in craft.tracker.rollUp.author(currentUser).all()
%}
{% endfor %}
```
#### List All Events By Entry
```twig
{% set entryId = 1 %}
-
{{ event.title }} -- {{ event.event }}
User Agent: {{ event.userAgent }}
IP: {{ event.remoteIp }}
OS: {{ event.clientOs }}
Created At: {{ event.dateCreated }}
Metadata:
-
{{ key }} - {{ value }}
{% for key, value in event.metadata|json_decode %}
{% endfor %}
-
{% for event in craft.tracker.query.entryId(entryId).all() %}
{% 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"} %}
$(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);
},
});
});
});
```