An open API service indexing awesome lists of open source software.

https://github.com/codeconut-ltd/angular-snippet-collection

Collection of components, directives and services for Angular. Handles Google Analytics custom event tracking and user preferences like colour scheme choice.
https://github.com/codeconut-ltd/angular-snippet-collection

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

Last synced: 2 months ago
JSON representation

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

Awesome Lists containing this project

README

        

![Angular Snippet Collection](teaser.png)

# Angular Snippet Collection

- [About](#about)
- [Features](#features)
- [Todo](#todo)


---

## 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

```ts
import { AbstractComponent } from 'abstract.component';

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

View

```html


  • {{item.id}}


```



---

### Directives

#### GoogleAnalytics / TrackEventDirective

Allow tracking custom events via Google Analytics.

##### Requirements

Services
- GoogleAnalyticsEventsService

##### Example

```html
Link
```



---

### 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
- [CookieConsent – Osano](https://www.npmjs.com/package/cookieconsent)

##### 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
- [CookieConsent – Osano](https://www.npmjs.com/package/cookieconsent)

---

#### Google Analytics events / GoogleAnalyticsEventsService

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

##### Example

```ts
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