ga-nav-tracker

2.1.0 • Public • Published

Google Analytics Nav Tracker (ga-nav-tracker)

Build Status npm

Auto-track link clicks for Google Analytics.

This library uses ga-track and needs Google Analytics to be set up in order to work.

Installation

npm install ga-nav-tracker

Usage

import GANavTracker from 'ga-nav-tracker'

init()

Initializes library and all link clicks within the specified tag will be tracked in Google Analytics.

Example (see example)

Add data-nav-tracker="header|footer" to any element and the library will track link clicks.

<nav>
  <ul data-nav-tracker="header">
    <li><a href="#">Link 1</a></li>
    <li><a href="#">Link 2</a></li>
  </ul>
</nav>

Clicking on the first link will be send this object to Google Analytics:

{
  action: 'header'
  label: 'Link 1'
  category: 'nav-tracker'
}

You can optionally set data-nav-tracker-dropdown, which prepends tracker location to the label property. See the example below:

<nav>
  <ul data-nav-tracker="header">
    <li><a href="#">Link 1</a></li>
    ...
    <li data-nav-tracker-dropdown="Dropdown">
      <ul>
        <li><a href="#">Link 2</a></li>
      </ul>
    </li>
  </ul>
</nav>

Clicking on the second link will send this object to Google Analytics:

{
  action: 'header'
  label: 'Dropdown - Link 2'
  category: 'nav-tracker'
}

License

MIT License

Copyright (c) 2019 First+Third

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Readme

Keywords

Package Sidebar

Install

npm i ga-nav-tracker

Weekly Downloads

7

Version

2.1.0

License

MIT

Unpacked Size

23 kB

Total Files

7

Last publish

Collaborators

  • aleperez92