-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
296 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<img | ||
src="../../../assets/svg/incendium.svg" | ||
alt="Incendium analytics logo" | ||
height="100px" | ||
width="200px" /> | ||
|
||
**homepage**: [incendium.ai](https://www.incendium.ai/) | ||
**import**: `import { Angulartics2Incendium } from 'angulartics2';` | ||
|
||
## Setup | ||
|
||
1. Add tracking code provided by Incendium inside the header tag. | ||
|
||
2. [Setup Angulartics](https://github.com/angulartics/angulartics2/tree/master#installation) using `Angulartics2Incendium` | ||
|
||
```typescript | ||
constructor(Angulartics2Incendium: Angulartics2Incendium) { | ||
Angulartics2Incendium.startTracking(); | ||
} | ||
``` | ||
|
||
3. Track Conversions, You can track conversions using Angulartics2 event tracking. | ||
this can be done by adding the following to you html | ||
|
||
```html | ||
<button | ||
angulartics2On="click" | ||
angularticsAction="{{ eIncendiumEventNames.ADD_CONVERION }}" | ||
[angularticsProperties]="{ key: 'my_trigger_as_assigned_in_incendium' }" | ||
> | ||
Btn click | ||
</button> | ||
``` | ||
|
||
Note that eIncendiumEventNames is a reference to IncendiumEventNames expoted from Angulartics2Incendium | ||
|
||
Or you can fire the conversion in code for example | ||
|
||
```typescript | ||
this.angulartics2.eventTrack.next({ | ||
action: IncendiumEventNames.ADD_CONVERION, | ||
properties: { | ||
key: 'my_trigger_as_assigned_in_incendium', | ||
}, | ||
}); | ||
``` | ||
|
||
4. Incendium allows for offline tracking, to do this you must record the conversion key provided when firing a conversion. | ||
A example of this would be a contact form which you later convert on the phone, incendium allows you to assign revenue next to this original conversion using this key | ||
|
||
to do this fire a conversion off as above. | ||
you can then subscribe to incendiumResponse. once the conversion has been tracked and response is returned you can use this response how ever you like. | ||
|
||
**_Dont forget to unsubscribe_** | ||
|
||
An Example workflow of this would be | ||
|
||
```typescript | ||
export class Example implements OnInit { | ||
private incSubscription; | ||
|
||
constructor( | ||
private angulartics2: Angulartics2, | ||
private angulartics2Incendium: Angulartics2Incendium, | ||
) {} | ||
|
||
ngOnInit(): void { | ||
this.incSubscription = this.angulartics2Incendium.incendiumResponse.subscribe({ | ||
next: v => { | ||
if (v.type === IncendiumEventNames.ADD_CONVERION) { | ||
this.submit(v.value); | ||
} | ||
}, | ||
error: e => { | ||
console.error(e); | ||
// submit without key or handle how you like | ||
this.submit(); | ||
}, | ||
}); | ||
} | ||
|
||
ngOnDestroy(): void { | ||
// Dont forget to unsubscribe | ||
this.incSubscription.unsubscribe(); | ||
} | ||
|
||
onSubmit() { | ||
this.angulartics2.eventTrack.next({ | ||
action: IncendiumEventNames.ADD_CONVERION, | ||
properties: { | ||
key: 'my_trigger_as_assigned_in_incendium', | ||
}, | ||
}); | ||
} | ||
|
||
submit(incendiumKey?: string) { | ||
alert(`form submitted with ${incendiumKey ? `key ${incendiumKey}` : `no key`}`); | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { fakeAsync, inject, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { Angulartics2 } from '../../angulartics2-core'; | ||
import { advance, createRoot, RootCmp, TestModule } from '../../test.mocks'; | ||
import { Angulartics2Incendium, IncendiumEventNames } from './incendium'; | ||
|
||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000; | ||
declare var window: any; | ||
|
||
describe('Angulartics2Incendium', () => { | ||
let inc: any; | ||
let fixture: ComponentFixture<any>; | ||
let service: Angulartics2Incendium; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [TestModule], | ||
providers: [Angulartics2Incendium], | ||
}); | ||
window.inc = inc = jasmine.createSpy('inc').and.returnValue('test'); | ||
|
||
service = TestBed.inject(Angulartics2Incendium); | ||
service.startTracking(); | ||
}); | ||
|
||
it('should track pages', fakeAsync( | ||
inject( | ||
[Angulartics2, Angulartics2Incendium], | ||
(angulartics2: Angulartics2, Angulartics2Incendium: Angulartics2Incendium) => { | ||
fixture = createRoot(RootCmp); | ||
angulartics2.pageTrack.next({ path: '/abc' }); | ||
advance(fixture); | ||
expect(inc).toHaveBeenCalledWith('run', false, true); | ||
}, | ||
), | ||
)); | ||
|
||
it('should track conversions', fakeAsync( | ||
inject( | ||
[Angulartics2, Angulartics2Incendium], | ||
(angulartics2: Angulartics2, Angulartics2Incendium: Angulartics2Incendium) => { | ||
fixture = createRoot(RootCmp); | ||
angulartics2.eventTrack.next({ | ||
action: IncendiumEventNames.ADD_CONVERION, | ||
properties: { key: 'test' }, | ||
}); | ||
advance(fixture); | ||
expect(inc).toHaveBeenCalledTimes(2); | ||
expect(inc).toHaveBeenCalledWith(IncendiumEventNames.ADD_CONVERION, 'test'); | ||
expect(inc).toHaveBeenCalledWith('go'); | ||
}, | ||
), | ||
)); | ||
|
||
it('should track conversion and emit conversion key', fakeAsync( | ||
inject( | ||
[Angulartics2, Angulartics2Incendium], | ||
(angulartics2: Angulartics2, Angulartics2Incendium: Angulartics2Incendium) => { | ||
service.incendiumResponse.subscribe(message => { | ||
expect(message).toEqual({ | ||
type: IncendiumEventNames.ADD_CONVERION, | ||
value: 'test', | ||
}); | ||
}); | ||
fixture = createRoot(RootCmp); | ||
angulartics2.eventTrack.next({ | ||
action: IncendiumEventNames.ADD_CONVERION, | ||
properties: { key: 'test' }, | ||
}); | ||
advance(fixture); | ||
}, | ||
), | ||
)); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Subject } from 'rxjs'; | ||
import { Angulartics2 } from '../../angulartics2-core'; | ||
|
||
enum EventNames { | ||
RUN = 'run', | ||
GO = 'go', | ||
} | ||
|
||
export enum IncendiumEventNames { | ||
ADD_CONVERION = 'add_conversion', | ||
} | ||
|
||
interface IIncendiumResponse { | ||
value: string; | ||
type: IncendiumEventNames; | ||
} | ||
|
||
type TIncendiumParams = | ||
| { | ||
key: string; | ||
} | ||
| boolean; | ||
|
||
declare var inc: (e: EventNames | IncendiumEventNames, v?: TIncendiumParams, g?: boolean) => string; | ||
declare global { | ||
interface Window { | ||
INCENDIUM: any; | ||
} | ||
} | ||
|
||
@Injectable({ providedIn: 'root' }) | ||
export class Angulartics2Incendium { | ||
incendiumResponse = new Subject<Partial<IIncendiumResponse>>(); | ||
|
||
constructor(private angulartics2: Angulartics2) { | ||
if (typeof inc === 'undefined') { | ||
console.warn('Angulartics 2 Incendium Plugin: incendium global not found'); | ||
} | ||
} | ||
|
||
startTracking(): void { | ||
this.angulartics2.pageTrack | ||
.pipe(this.angulartics2.filterDeveloperMode()) | ||
.subscribe(x => this.pageTrack(x.path)); | ||
|
||
this.angulartics2.eventTrack | ||
.pipe(this.angulartics2.filterDeveloperMode()) | ||
.subscribe(({ action, properties }) => this.trackAction(action, properties)); | ||
} | ||
|
||
/** | ||
* Track Page in Incendium | ||
* | ||
* @param path location | ||
*/ | ||
pageTrack(path: string) { | ||
inc(EventNames.RUN, false, true); | ||
} | ||
|
||
/** | ||
* Track Action | ||
* | ||
* @param action Action name | ||
* @param properties params | ||
*/ | ||
async trackAction(action: string, properties: any) { | ||
try { | ||
switch (action as IncendiumEventNames) { | ||
case IncendiumEventNames.ADD_CONVERION: | ||
inc(IncendiumEventNames.ADD_CONVERION, properties.key); | ||
break; | ||
|
||
default: | ||
break; | ||
} | ||
const res = await inc(EventNames.GO); | ||
this.incendiumResponse.next({ | ||
value: res, | ||
type: IncendiumEventNames.ADD_CONVERION, | ||
}); | ||
} catch (error) { | ||
this.incendiumResponse.error(error); | ||
} | ||
} | ||
} |