1

Context:

I'm implementing a BI telemetry/logging library as an Angular2 service. The goal is to get a PageView event to fire every time I visit a new "page" within my app.

To do that, I'm currently putting a subscribe on the router's events (basically doing what was recommended in this answer). My pageviews are now firing correctly on navigation.

Current problem:

Part of my PageView's payload is to show the content contained within that page. Therefore my service needs to have some way to "inspect" arbitrary components within the app.

Based on my limited understanding of Angular2, it's not at all clear what would be a reasonable approach for this.

I'm wondering if "inspecting arbitrary app components from a service" is something that's been solved before, for some other problem.

Community
  • 1
  • 1
nciao
  • 581
  • 4
  • 22

1 Answers1

0

Answering my own question:

I ended up implementing my own attribute directive which allows component authors to annotate their html with the relevant data.

This contextual data is then "pushed" by the directive into my telemetry service (by way of an rxjs Observable). The telemetry service then handles all the logging.

nciao
  • 581
  • 4
  • 22