UNPKG

2.39 kBMarkdownView Raw
1<img
2 src="../../../assets/svg/splunk.svg"
3 alt="Splunk logo"
4 height="100px"
5 width="200px" />
6
7# Splunk
8__homepage__: [splunk.com](https://www.splunk.com/)
9__docs__: [Splunk Collector API](https://github.com/splunk/splunk-demo-collector-for-analyticsjs#api)
10__import__: `import { Angulartics2Splunk } from 'angulartics2/splunk';`
11
12## Setup
131. Add tracking code [provided by Splunk](https://www.splunk.com/blog/2013/10/17/still-using-3rd-party-web-analytics-providers-build-your-own-using-splunk.html) to right above the `</head>` closing tag.
14 ```
15 <script type="text/javascript"> var sp=sp||[];(function(){var e=["init","identify","track","trackLink","pageview"],t=function(e){return function(){sp.push([e].concat(Array.prototype.slice.call(arguments,0)))}};for(var n=0;n<e.length;n++)sp[e[n]]=t(e[n])})(),sp.load=function(e,o){sp._endpoint=e;if(o){sp.init(o)};var t=document.createElement("script");t.type="text/javascript",t.async=!0,t.src=("https:"===document.location.protocol?"https://":"http://")+"d21ey8j28ejz92.cloudfront.net/analytics/v1/sp.min.js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(t,n)};
16 sp.load("https://www.example.com"); // Replace with your own collector URL
17 </script>
18 ```
19 In the last line of above script, make sure to replace https://www.example.com with the address of your data collector.
20
212. [Setup Angulartics](https://github.com/angulartics/angulartics2/tree/next#installation) using `Angulartics2Splunk`.
22```ts
23import { NgModule } from '@angular/core';
24import { BrowserModule } from '@angular/platform-browser';
25import { RouterModule, Routes } from '@angular/router';
26
27import { Angulartics2Module } from 'angulartics2';
28
29const ROUTES: Routes = [
30 { path: '', component: HomeComponent },
31 { path: 'about', component: AboutComponent },
32];
33
34@NgModule({
35 imports: [
36 BrowserModule,
37 RouterModule.forRoot(ROUTES),
38
39 // added to imports
40 Angulartics2Module.forRoot(),
41 ],
42 declarations: [AppComponent],
43 bootstrap: [AppComponent],
44})
45```
463. __Required__: Import your providers in the root component. This starts the tracking of route changes.
47```ts
48// component
49import { Angulartics2Splunk } from 'angulartics2/splunk';
50
51@Component({ ... })
52export class AppComponent {
53 constructor(angulartics2Splunk: Angulartics2Splunk) {
54 angulartics2Splunk.startTracking();
55 }
56}
57```