Giter VIP home page Giter VIP logo

ngx-metrika's Introduction

Angular Yandex Metrika

npm version Build Status Coverage Status codecov

A simple Yandex Mertika (Яндекс Метрика) tag.js package for Angular 6+.

Demo

Demo is here demo

Working code for this demo at stackblitz example

Install

Install via npm package manager

npm install @kolkov/ngx-metrika --save

Add the package to your app.module.ts. Then simple add property yaCounterId to the environment constant or use inline

import { RouterModule } from '@angular/router';
import { NgxMetrikaModule } from '@kolkov/ngx-metrika';

@NgModule({
  imports: [
    RouterModule.forRoot([]),
    NgxMetrikaModule.forRoot({
      id: environment.yaCounterId,
      ...      
      defer: true,
      webvisor: true,
      clickmap: true,
      trackLinks: true,
      accurateTrackBounce: true,
    })
  ]
})

Pageviews

The package will listen to route changes by default, you just need to instantiate service in the root of the project.

export class AppComponent {
  constructor(private ym: NgxMetrikaService) { }
}

NgxMetrika is a service that also allows you to track pageviews manually.

this.ym.hit.emit();

// or with custom params

this.ym.hit.emit({url: '/custom',{
  title: 'Lesson Feed',  
  referer: 'https://angularfirebase.com/lessons'
}});

ReachGoal

ReachGoal expect an action.

this.ym.reachGoal.next({target: 'TARGET_NAME'})

You can optionally pass in addtional params.

function goalCallback () {
        console.log('request to Metrika sent successfully');
    }
const options: CommonOptions = {     
         params: {
            productId: product.id,
            productName: product.name,
         },
         callback: goalCallback,
      }
this.ym.reachGoal.next({target: 'ADD_TO_CART', options});

Goal Directive

Many analytics events are tracked based on user interaction, such as button clicks. Just tell it which DOM event to track.

<button ymGoal trackOn="click" target="TRACKED">Track Me</button>

This will register a general Target in Yandex Metrika based on the target name.

You can pass optional params to the directive like so:

<div ymGoal     
     target="PROGUCT_DRAGGED"     
     [params]="{ targetLabel: 'Something cool just happened' }">

   Some Product...
   
</div>

The directive will produce the following event on dragstart.

What's included

Within the download you'll find the following directories and files. You'll see something like this:

metrika/
└── projects/
    ├── ngx-metrika/
    └── ngx-metrika-app/

ngx-metrika/ - library

ngx-metrika-app/ - demo application

Documentation

The documentation for the ngx-metrika is hosted at our website ngx-metrika

Contributing

Please read through our contributing guidelines. Included are directions for opening issues, coding standards, and notes on development.

Editor preferences are available in the editor config for easy use in common text editors. Read more and download plugins at http://editorconfig.org.

Versioning

For transparency into our release cycle and in striving to maintain backward compatibility, ngx-metrika is maintained under the Semantic Versioning guidelines.

See the Releases section of our project for changelogs for each release version.

Creators

Andrey Kolkov

ngx-metrika's People

Contributors

kolkov avatar un-def avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ngx-metrika's Issues

Version 1.0.5 incompatible with ngUniversal on Angular 13

Hello,

There is a recent release for Angular 12 compatibility v0.5.3 but none for version 13.

npm ERR! Found: @angular/[email protected]
npm ERR! node_modules/@angular/common
npm ERR!   @angular/common@"~13.3.3" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer @angular/common@">=8.0.0 <13" from @kolkov/[email protected]
npm ERR! node_modules/@kolkov/ngx-metrika
npm ERR!   @kolkov/ngx-metrika@"^0.5.3" from the root project

Is it possible to create a release as well?

Cheers

Angular 14

./node_modules/@kolkov/ngx-metrika/fesm2020/kolkov-ngx-metrika.mjs:130:39-48 - Error: export 'scriptUrl' (imported as 'scriptUrl') was not found in 'safevalues' (possible exports: EMPTY_HTML, EMPTY_SCRIPT, HtmlSanitizerBuilder, SafeAttributePrefix, SafeHtml, SafeScript, SafeStyle, SafeStyleSheet, TrustedResourceUrl, appendParams, blobUrlFromScript, concatHtmls, concatScripts, concatStyleSheets, concatStyles, createScript, createScriptSrc, htmlEscape, isHtml, isResourceUrl, isScript, isStyle, isStyleSheet, replaceFragment, safeAttrPrefix, safeScript, safeScriptWithArgs, safeStyle, safeStyleSheet, sanitizeHtml, sanitizeHtmlAssertUnchanged, sanitizeHtmlToFragment, scriptFromJson, trustedResourceUrl, unwrapAttributePrefix, unwrapHtml, unwrapResourceUrl, unwrapScript, unwrapStyle, unwrapStyleSheet)

No Screen Recordings Show Up

When using this package,
I don't get any screen recordings in Yandex Metrika dashboard.

I didn't have time to get into this too much (and couldn't because #3),
but when using ng-yandex-metrika, screen recordings do show up.

Can you investigate this?

Proper Angular CLI

Anyone who wants to contribute to this project, is going to have a hard time, setting this repository on their local machine.
Please upload the whole project, not just the library part.

This will allow developers to run ng test, and also work with the demo app.
Structure it more like you did on your other repo.
While you upload the whole source to github, when you want to deploy to npm, you only deploy the dist.

Thank you for your great work on this project.

Module not found: Error: Can't resolve 'safevalues'

./node_modules/@kolkov/ngx-metrika/fesm2020/kolkov-ngx-metrika.mjs:8:0-63 - Error: Module not found: Error: Can't resolve 'safevalues' in '/home/artem/go/src/repo.aleksashkin.net/prepropost-api/ui/node_modules/@kolkov/ngx-metrika/fesm2020'

error appears in angular 15. Plz fix.

Uncaught TypeError: Object(...) is not a function

"@angular/animations": "^6.1.1",
"@angular/common": "^6.1.1",
"@angular/compiler": "^6.1.1",
"@angular/core": "^6.1.1",
"@angular/forms": "^6.1.1",
"@angular/http": "^6.1.1",
"@angular/platform-browser": "^6.1.1",
"@angular/platform-browser-dynamic": "^6.1.1",
"@angular/router": "^6.1.1",
"@kolkov/ngx-metrika": "^0.5.2",

Виділення_145

Error with Angular Universal

Hi, everyone.

I have a trouble when trying to generate static pre-render with Angular Universal

ERROR ReferenceError: window is not defined
    at NgxMetrikaService.insertMetrika (webpack:///./node_modules/@kolkov/ngx-metrika/fesm5/kolkov-ngx-metrika.js?:202:9)
    at NgxMetrikaService.configure (webpack:///./node_modules/@kolkov/ngx-metrika/fesm5/kolkov-ngx-metrika.js?:85:14)
    at new NgxMetrikaService (webpack:///./node_modules/@kolkov/ngx-metrika/fesm5/kolkov-ngx-metrika.js?:48:18)
    at _createClass (webpack:///./node_modules/@angular/core/fesm5/core.js?:20931:20)
    at _createProviderInstance (webpack:///./node_modules/@angular/core/fesm5/core.js?:20893:26)
    at resolveNgModuleDep (webpack:///./node_modules/@angular/core/fesm5/core.js?:20856:21)
    at NgModuleRef_.get (webpack:///./node_modules/@angular/core/fesm5/core.js?:21547:16)
    at resolveDep (webpack:///./node_modules/@angular/core/fesm5/core.js?:21918:45)
    at createClass (webpack:///./node_modules/@angular/core/fesm5/core.js?:21790:29)
    at createDirectiveInstance (webpack:///./node_modules/@angular/core/fesm5/core.js?:21669:20)
Unhandled Promise rejection: window is not defined ; Zone: <root> ; Task: Promise.then ; Value: ReferenceError: window is not defined
    at NgxMetrikaService.insertMetrika (webpack:///./node_modules/@kolkov/ngx-metrika/fesm5/kolkov-ngx-metrika.js?:202:9)
    at NgxMetrikaService.configure (webpack:///./node_modules/@kolkov/ngx-metrika/fesm5/kolkov-ngx-metrika.js?:85:14)
    at new NgxMetrikaService (webpack:///./node_modules/@kolkov/ngx-metrika/fesm5/kolkov-ngx-metrika.js?:48:18)
    at _createClass (webpack:///./node_modules/@angular/core/fesm5/core.js?:20931:20)
    at _createProviderInstance (webpack:///./node_modules/@angular/core/fesm5/core.js?:20893:26)
    at resolveNgModuleDep (webpack:///./node_modules/@angular/core/fesm5/core.js?:20856:21)
    at NgModuleRef_.get (webpack:///./node_modules/@angular/core/fesm5/core.js?:21547:16)
    at resolveDep (webpack:///./node_modules/@angular/core/fesm5/core.js?:21918:45)
    at createClass (webpack:///./node_modules/@angular/core/fesm5/core.js?:21790:29)
    at createDirectiveInstance (webpack:///./node_modules/@angular/core/fesm5/core.js?:21669:20) ReferenceError: window is not defined
    at NgxMetrikaService.insertMetrika (webpack:///./node_modules/@kolkov/ngx-metrika/fesm5/kolkov-ngx-metrika.js?:202:9)
    at NgxMetrikaService.configure (webpack:///./node_modules/@kolkov/ngx-metrika/fesm5/kolkov-ngx-metrika.js?:85:14)
    at new NgxMetrikaService (webpack:///./node_modules/@kolkov/ngx-metrika/fesm5/kolkov-ngx-metrika.js?:48:18)
    at _createClass (webpack:///./node_modules/@angular/core/fesm5/core.js?:20931:20)
    at _createProviderInstance (webpack:///./node_modules/@angular/core/fesm5/core.js?:20893:26)
    at resolveNgModuleDep (webpack:///./node_modules/@angular/core/fesm5/core.js?:20856:21)
    at NgModuleRef_.get (webpack:///./node_modules/@angular/core/fesm5/core.js?:21547:16)
    at resolveDep (webpack:///./node_modules/@angular/core/fesm5/core.js?:21918:45)
    at createClass (webpack:///./node_modules/@angular/core/fesm5/core.js?:21790:29)
    at createDirectiveInstance (webpack:///./node_modules/@angular/core/fesm5/core.js?:21669:20)

Can anybody help me?

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.