Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/components/templates/LandingPageOne/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,12 @@ function LandingPage(props: LandingPageProps) {

// optional props
origin="Landing Page"
// context="AntD Card"
dataContext={{
app: {
version: "0",
},
context: "Custom Landing page"
}}
/>,
]}>

Expand Down
36 changes: 28 additions & 8 deletions src/components/templates/LoginForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ function LoginForm(props: LoginFormProps) {

// optional props
origin="Login Button"
// context="AntD Card"
dataContext={{
app: {
version: "0",
},
context: "Custom login page"
}}
/>,
<Button
type="ghost"
Expand All @@ -75,16 +80,31 @@ function LoginForm(props: LoginFormProps) {
type="text"
placeholder="email"

trackers={[{
action: "onClick",
track: logEvent,
data: {
customKey1: "input",
trackers={[
{
action: "onClick",
track: logEvent,
data: {
customKey1: "input",
}
},
{
action: "onChange",
track: logEvent,
data: {
customKey1: "input",
}
}
}]}
]}

// optional props
origin="Email Input"
origin="Login Page Email Input"
dataContext={{
app: {
version: "0",
},
context: "Custom login page"
}}
/>
<Input
type="password"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
export function getUserOS() {
interface OSDetails{
name: string;
version: string;
}

export function getUserOS() : OSDetails {
const userAgent = window.navigator.userAgent;
const platform = window.navigator.platform;
const macosPlatforms = ["Macintosh", "MacIntel", "MacPPC", "Mac68K"];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default interface UserInteractionResource extends BaseResource {
action: UserInteraction.Action;
source: {
context: string;
origin: string;
origin?: string;
component: string;
element: {
currentTarget: string;
Expand Down
19 changes: 12 additions & 7 deletions src/library/user-analytics/react/components/withTracking.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import { DataContext } from '../contexts/dataContext';

type TrackerProps = {
context?: string,
dataContext?: UserInteraction.DataContext;
origin?: string,
trackers: UserInteraction.Tracker[]
} & Object<any>;
Expand All @@ -18,10 +18,13 @@ export function withTracking (
) {
return function Fn(props: TrackerProps) {
let eventHandlers: Object<any> = {};
const { trackers, ...originalProps } = props;
const { trackers, origin, dataContext: dataContextFromProps, ...originalProps } = props;

const dataContext = useContext(DataContext);
const context = props.context ? props.context : dataContext.context;
let dataContext = useContext(DataContext);

if (dataContextFromProps) {
dataContext = dataContextFromProps
}

function trackUserInteraction(
e: React.SyntheticEvent,
Expand All @@ -33,8 +36,10 @@ export function withTracking (
dataContext.app,
tracker.action,
{
context,
origin: originalProps.origin || "",
context: dataContext.context,
...(originalProps.origin && {
origin: originalProps.origin
}),
component: Component.displayName || Component.name,
element: {
currentTarget: e.currentTarget.nodeName,
Expand Down Expand Up @@ -63,7 +68,7 @@ export function withTracking (

return (
<Component
{ ...props }
{ ...originalProps }
{ ...eventHandlers }
/>
);
Expand Down