-
Notifications
You must be signed in to change notification settings - Fork 11
/
Page.tsx
79 lines (71 loc) · 2.41 KB
/
Page.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import EpiComponent from './EpiComponent';
import IContent from './Models/IContent';
export enum PageType {
Home = "home",
Product = "product",
Category = "category",
Basket = "basket",
Other = "other"
}
export default abstract class Page<P extends IContent, S = {}> extends EpiComponent<P, S>
{
/**
* The page type of the current page being rendered
*/
protected pageType: PageType = PageType.Other;
/**
* Make sure page tracking is done when a page is being rendered
*
* This method cannot be overridden in sub-classes, use the pageDidMount method, that
* is invoked by this class as direct replacement.
*/
public readonly componentDidMount = (): void =>
{
/*let initialContent = EpiContext.Instance.getInitialContentLink();
if (!(initialContent && initialContent.guidValue == this.props.data.contentLink.guidValue)) {
//Only track if we're not the initial page
let trackingData = this.buildTrackingData();
if (this.isDebugActive()) {
console.debug("ProductRecs tracking data: ", trackingData);
}
if (trackingData) Engine.trackPageView(trackingData);
}*/
if (this.pageDidMount) this.pageDidMount();
}
/**
* This method creates the tracking data as send to the the Episerver tracking service
*/
protected readonly buildTrackingData = () : any =>
{
let trackingData : any = {};
if (this.pageWillTrack) trackingData = this.pageWillTrack(trackingData);
return trackingData;
}
/**
* Retrieve the path of the current page
*/
protected readonly getPagePath = () : string =>
{
return this.getCurrentContentLink().url;
}
/**
* Build an action URL
*/
protected readonly buildActionPath = (action: string) : string =>
{
return (this.getPagePath() + '/' + action + '/').replace('//', '/');
}
/**
* Lifecycle call, implement this method instead of the React standard
* componentDidMount.
*/
protected pageDidMount?() : void
/**
* Lifecycle call, invoked just before the page will be tracked. It should
* return the tracking data for the page. If nothing is returned, the page
* will not be tracked.
*
* @param data The initial data for tracking
*/
protected pageWillTrack?(data: any) : any
}