0.0.4 • Published 8 years ago

lytix v0.0.4

Weekly downloads
6
License
MIT
Repository
github
Last release
8 years ago

Lytix

Avoid dealing with vendor-specific Web analytics tracking codes

Lytix encapsulates tracking codes so you’re able to switch your Web analytics vendor without changing all your tracking. All you need to do is switch the vendor adapter. It’s inspired by Angulartics but runs without any framework.

Download

To get going with Lytix you can:

Usage

Embed lytix.js and the Lytix adapter for your vendor within your Web site or Web application. In addition, make sure you deleted any automatic tracking line from your vendor snippet code (e.g. ga('send', 'pageview'); for Google Analytics).

<script src="lytix.js"></script>
<script src="lytix-google.js"></script>

If you’re using a build tool (like Grunt or gulp), you may concatenate and minify the files combined with your other scripts into a single file in order to reduce the amount of requests.

Declarative event tracking

Each vendor has its own set of tracking properties. However, lytix-on always needs to be present as it is the attribute that enables event tracking for the element. All other attributes may be omitted, depending on your analytics provider.

<a href="file.pdf" lytix-on="click" lytix-category="Download" lytix-label="Demo123.zip">Download</a>

Using lytix-on and lytix-event is especially useful when working with custom events. Depending on your analytics adapter, the adapter may use lytix-event instead of lytix-on for the event/action name while Lytix still listens to your custom event specified in lytix-on.

<label for="demo">
    <input type="checkbox" id="demo" lytix-on="change" lytix-event="click" lytix-category="Checkbox" lytix-label="confirm_terms">
    Demo
</label>
ga('send', 'event', {
    …
    eventAction: properties.event || properties.action || null,
    …
});

Attributes

Instead of lytix-{XYZ} attributes, you may also use tracking-{XYZ} or analytics-{XYZ}. In addition, you can use data-lytix-{XYZ}, data-tracking-{XYZ}, or data-analytics-{XYZ}. In the end, it’s all the same.

Using the API

In order to track page views and events programmatically from within your application logic, you can use the global lytix object and invoke either the trackPage() or trackEvent() methods.

lytix.trackPage('/some/url');
lytix.trackEvent({
  action: 'click',
  category: 'Some category',
  label: 'Some label'
});

Settings

Lytix tracks the initial/first page view by default. In addition, Lytix does automatic virtual page view tracking by default, meaning the entire user navigation across the different routes of your application gets tracked. You can turn this behavior off modifying the following setting properties.

SettingDefaultPurpose
lytix.settings.autoTrackFirstPagetrueDecide whether the initial page view shall be tracked or not
lytix.settings.autoTrackVirtualPagestrueTrack virtual page views (e.g. example.com/#!/about-us will be tracked as /about-us)
<script src="lytix.js"></script>
<script>
lytix.settings.autoTrackFirstPage = false;
lytix.settings.autoTrackVirtualPages = true;
</script>
<script src="lytix-google.js"></script>

Plugins

VendorPage tracking supported?Event tracking supported?File
Adobe Analytics (Omniture)YesYeslytix-adobe.js
BaiduYesYeslytix-baidu.js
ChartbeatYesNolytix-chartbeat.js
CNZZYesYeslytix-cnzz.js
FlurryNoYeslytix-flurry.js
HubSpotYesYeslytix-hubspot.js
Google AnalyticsYesYeslytix-google.js
KISSmetricsYes (via event tracking)Yeslytix-kissmetrics.js
LocalyticsYesYeslytix-localytics.js
LogglyYesYeslytix-loggly.js
MixpanelYes (via event tracking)Yeslytix-mixpanel.js
PiwikYesYeslytix-piwik.js
SegmentYesYeslytix-segment.js
SplunkYesYeslytix-splunk.js
Trak.ioYesYeslytix-trakio.js
WoopraYesYeslytix-woopra.js

lytix-debugging.js is a special plugin that logs everything that happens to the browser console. It’s intended to support you while testing/debugging your tracking.

Contributing

If your analytics vendor of choice is not among the existing plugins, feel free to write your own and create a PR on GitHub. It’ll be most welcomed!

Changelog

  • 0.0.4
    • Fix typo in README
  • 0.0.3
    • npm support
    • Bower support
  • 0.0.2
    • Add adapters for Baidu, Chartbeat, CNZZ, Flurry, HubSpot, KISSmetrics, Localytics, Loggly, Mixpanel, Segment, Splunk, Trak.io and Woopra
    • Fix README
    • Clean up
  • 0.0.1
    • Initial version

TODO

  • Documentation
  • Tests

License

Copyright (c) 2016 websperts
Licensed under the MIT license.

See LICENSE for more info.