mykeels / ga-click

An alternative to embedding JavaScript in your HTML via `onclick` attributes when working with Google Analytics

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ga-Click

An alternative to embedding JavaScript in your HTML via onclick attributes when working with Google Analytics. Click here to see demo.

Getting started

Clone this repository.

Add to and Edit the demo event objects in the EVENTS dictionary object in the ga-click.js file.

Each item in the EVENTS object has a Key which is a string that should be in camelCase, and a Value which is an object containing the following properties:

  • Label: A string that describes the GA Event to be tracked.
  • Action: A function that executes the corresponding GA Command.

Add a reference of your resultant script to your web page!

On each element you need to track add a ga-click attribute, and the Label of the event you intend that element to represent. E.g. I could add ga-click='liked' to my Like button.

Execute your web page.

You now have the power of Google Analytics without the headaches that inline JavaScript brings.

Enjoy!

Author(s)

  • Ikechi Michael I.

About

An alternative to embedding JavaScript in your HTML via `onclick` attributes when working with Google Analytics


Languages

Language:JavaScript 56.8%Language:HTML 32.6%Language:CSS 10.6%