digital-analytics-program / gov-wide-code

Provides a set of javascript files and documentation to implement web analytics on US federal websites
http://www.digital.gov/dap
104 stars 55 forks source link

Angular 2 - Virtual page view tracking #59

Closed skolli853780 closed 7 years ago

skolli853780 commented 7 years ago

Hello,

We are using Digital analytics-program in our application, it works well for individual pages.. since our application is developed using Angular 2, we do not reload the whole page when a button is clicked.. I have looked at the documentation about Virtual pageview tracking.. one of the parameters gas function takes is url.. we use angular Routerlink to navigate between pages.. Is there a way we can pass Routerlink instead of URL? please advise

Thanks SK

tdlowden commented 7 years ago

Hi. Single-page app libraries like Angular and React do pose some problems for pageview tracking. I'm not familiar with Routerlink, but I have seen some folks use Angulartics to help with virtual pageviews. Alternatively, you can send virtual pageviews with a gas function by coding it yourself. Documentation can be found on page 14 of our Code Capabilities Summary

tdlowden commented 7 years ago

Let us know how it goes!

skolli853780 commented 7 years ago

Can we use Angulartics along with your program? we have been asked to use DAP for Google analytics

tdlowden commented 7 years ago

You can. You just need to configure it to send the pageviews to the DAP UA ID. :)

skolli853780 commented 7 years ago

how is your program different from Google analytics code..

can I replace https://www.google-analytics.com/analytics.js with DAP js file? please advise.. I tried Angulartics, there is some issue with our version of Angular..

tdlowden commented 7 years ago

Please read the instructions in the README. You don't use normal GA block to run DAP, you use our own custom <script> that calls our code either locally or from our central location.