Skip to content

Instantly share code, notes, and snippets.

Created February 22, 2018 16:27
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Aurelia Custom Attribute for registering events with Google Universal Analytics
import {autoinject, bindable} from "aurelia-framework";
declare const ga: (
command: "send",
type: "event",
category?: string,
action?: string,
label?: string,
) => void;
export class AnalyticsCustomAttribute {
on = "click";
@bindable({primaryProperty: true})
event?: string;
category?: string;
label?: string;
private listener: (event: Event) => void;
constructor(private element: Element) {
this.listener = this.onEvent.bind(this);
bind() {
this.element.addEventListener(this.on, this.listener);
unbind() {
this.element.removeEventListener(this.on, this.listener);
onEvent() {
ga("send", "event", this.category, this.event, this.label);
return true;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment