Giter Site home page Giter Site logo

codeconut-ltd / angular-snippet-collection Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 65 KB

Collection of components, directives and services for Angular. Handles Google Analytics custom event tracking and user preferences like colour scheme choice.

License: MIT License

TypeScript 97.23% HTML 2.77%
angular angular9 angular-snippets angular-directive angular-component angular-service typescript js javascript cookie-consent google-analytics osano cookieconsent snippets angular-directives event-tracking color-scheme user-tracking component ecmascript6

angular-snippet-collection's Introduction

Angular Snippet Collection

Angular Snippet Collection



About

Collection of small helper components, directives and services that might be published in a more convenient format via NPM in the future.

Tested with Angular 8-9

Setup

Manually copy and integrate these files in your own Angular setup.

Make sure to set the correct import paths for requirements. Some classes need to be integrated in the main application module and component. Watch out for 'todo' comments where custom data is required.




Features

Components

AbstractComponent

Use with view components. Applies trackByFn to improve list rendering performance.

Example

Component

import { AbstractComponent } from 'abstract.component';

@Component(...)
export class UiNavigationFooterComponent extends AbstractComponent {
...

View

<ul>
  <li *ngFor="let item of items; trackBy: trackByFn">{{item.id}}</li>
</ul>




Directives

GoogleAnalytics / TrackEventDirective

Allow tracking custom events via Google Analytics.

Requirements

Services

  • GoogleAnalyticsEventsService
Example
<a [appTrackEvent]="['UI module', 'Click', link.name, 1]">Link</a>




Services

Cookie consent / CookieConsentService

Angular wrapper for the NPM plugin, including a little tweak (yep, dirty) to also respect the 'do not track signal' users might set. In this case, cookies will always be declined. A better way would be to change the cookie banner text as well.

Todo: Decouple dependency, optimize display.

Requirements
  • global.d.ts

Services

  • UserTrackPreferenceService

External

Example

Google Analytics / GoogleAnalyticsService

Enables Google Analytics and defines a custom datalayer variable. Respects user opt-in from 'cookie consent'.

Requirements
  • index.html
  • global.d.ts

Services

  • CookieConsentService
  • GoogleAnalyticsEventsService

External


Google Analytics events / GoogleAnalyticsEventsService

Allows tracking custom and navigation change events. Custom events can be tracked via TrackEventDirective.

Example
export class ExampleComponent {
  constructor( private googleAnalyticsEventsService: GoogleAnalyticsEventsService ) {
  }

  track( event: any ) {
    const eventData = ['UI module', 'Click', 'EVENT VALUE', 1];

    this.googleAnalyticsEventsService.trackCustomEvent( eventData );
  }
}

User colour scheme / UserColorSchemeService

Set user colour scheme preference as CSS class. It will be stored and loaded from cookie as well. The information is useful for theming websites and applying 'light switches'.

Todo: Move to LocalStorage instead, no need for cookies here.


User track preference / UserTrackPreferenceService

Retrieve 'do not track signal' from user settings. Used to disable tracking implementations in other services.




Todo

  • Integrate ESLint + TypeScript with Prettier

angular-snippet-collection's People

Contributors

christianoellers avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.