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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 43 additions & 6 deletions src/layout/Dashboard/Drawer/DrawerContent/NavCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,15 @@ import {
getLocalActiveAPI,
setLocalActiveAPI,
getLocalLaunchCode,
setLocalLaunchCode
setLocalLaunchCode,
getLocalGroupType,
setLocalGroupType,
getLocalGroupName,
setLocalGroupName,
getLocalGroupProperty,
setLocalGroupProperty,
getLocalGroupPropertyValue,
setLocalGroupPropertyValue
} from 'utils/localStorage';

export default function NavCard() {
Expand All @@ -53,12 +61,16 @@ export default function NavCard() {
const [userSlug, setUserSlug] = useState(getLocalUserSlug());
const [localSDK, setLocalSDK] = useState(getLocalSDKKey());
const [launchCode, setLaunchCode] = useState(getLocalLaunchCode());
const [groupType, setGroupType] = useState(getLocalGroupType());
const [groupName, setGroupName] = useState(getLocalGroupName());
const [groupProperty, setGroupProperty] = useState(getLocalGroupProperty());
const [groupPropertyValue, setGroupPropertyValue] = useState(getLocalGroupPropertyValue());

useEffect(() => {
// Set the current launch code in localStorage on page load/refresh
setLocalLaunchCode(launchCode);

const analyticsHost = localSDK === 'staging' ? 'https://api.stag2.amplitude.com/2/httpapi' : undefined;
const analyticsHost = activeAPI === 'staging' ? 'https://api.stag2.amplitude.com/2/httpapi' : undefined;

const decideHostMap = {
local: 'http://localhost:10001',
Expand Down Expand Up @@ -110,12 +122,25 @@ export default function NavCard() {

amplitude.identify(identifyEvent);

// Put the user in a group, and set a property on the group (not the user) for group property targeting
if (groupType && groupName) {
amplitude.setGroup(groupType, groupName);
if (groupProperty) {
amplitude.groupIdentify(groupType, groupName, new amplitude.Identify().set(groupProperty, groupPropertyValue));
Comment on lines +126 to +129
}
}

console.log('Local SDK is integrated with Amplitude', activeAPIKey, decideHost);
}

// Engagement SDK Router
if (window.engagement) {
window.engagement.setRouter((newUrl) => navigate(newUrl));

// Callback tool the AI agent can invoke client-side.
window.engagement.registerCallbackTool('test_callback_tool', (args) => {
console.log('registerCallbackTool', args);
});
} else {
console.warn('window.engagement is not available for router and boot setup.');
}
Expand All @@ -133,7 +158,7 @@ export default function NavCard() {
return () => {
console.log('NavCard unmounted');
};
}, [activeAPI, localKey, stagingKey, prodKey, userSlug, localSDK, launchCode, navigate]);
}, [activeAPI, localKey, stagingKey, prodKey, userSlug, localSDK, launchCode, groupType, groupName, groupProperty, groupPropertyValue, navigate]);

const handleInputChange = (e) => {
const { name, value } = e.target;
Expand All @@ -144,7 +169,11 @@ export default function NavCard() {
userSlug: setLocalUserSlug,
activeAPI: setLocalActiveAPI,
localSDK: setLocalSDKKey,
launchCode: setLocalLaunchCode
launchCode: setLocalLaunchCode,
groupType: setLocalGroupType,
groupName: setLocalGroupName,
groupProperty: setLocalGroupProperty,
groupPropertyValue: setLocalGroupPropertyValue
};
setters[name](value);
const stateSetters = {
Expand All @@ -154,7 +183,11 @@ export default function NavCard() {
userSlug: setUserSlug,
activeAPI: setActiveAPI,
localSDK: setLocalSDK,
launchCode: setLaunchCode
launchCode: setLaunchCode,
groupType: setGroupType,
groupName: setGroupName,
groupProperty: setGroupProperty,
groupPropertyValue: setGroupPropertyValue
};
stateSetters[name](value);
};
Expand Down Expand Up @@ -215,7 +248,11 @@ export default function NavCard() {
{ id: 'localKey', label: 'Local API Key', value: localKey },
{ id: 'stagingKey', label: 'Staging API Key', value: stagingKey },
{ id: 'prodKey', label: 'Production API Key', value: prodKey },
{ id: 'userSlug', label: 'User Slug', value: userSlug }
{ id: 'userSlug', label: 'User Slug', value: userSlug },
{ id: 'groupType', label: 'Group Type', value: groupType },
{ id: 'groupName', label: 'Group Name', value: groupName },
{ id: 'groupProperty', label: 'Group Property', value: groupProperty },
{ id: 'groupPropertyValue', label: 'Group Property Value', value: groupPropertyValue }
].map(({ id, label, value }) => renderInputField(id, label, value))}
<FormControl sx={{ mt: 2, width: '100%' }}>
<InputLabel htmlFor="activeAPI">Active API</InputLabel>
Expand Down
36 changes: 36 additions & 0 deletions src/utils/localStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ const LOCALSTORAGE_USER_SLUG = 'test-base-user';
const END_USER_API = 'engagement.dev_base_app.end_user_api';
const LOCALSTORAGE_INTEGRATION = 'engagement.dev_base_app.integration';
const LOCALSTORAGE_EUS_LOCATION = 'amplitude.engagement.eus_location';
const LOCALSTORAGE_GROUP_TYPE = 'engagement.dev_base_app.group_type';
const LOCALSTORAGE_GROUP_NAME = 'engagement.dev_base_app.group_name';
const LOCALSTORAGE_GROUP_PROPERTY = 'engagement.dev_base_app.group_property';
const LOCALSTORAGE_GROUP_PROPERTY_VALUE = 'engagement.dev_base_app.group_property_value';

export const setLocalStorage = (key, value) => {
if (window !== 'undefined') {
Expand Down Expand Up @@ -128,3 +132,35 @@ export const setLocalLaunchCode = (value) => {
setLocalStorage(LOCALSTORAGE_LAUNCH_CODE, launchCodeValue);
}

// Group (setGroup / groupIdentify)
export const getLocalGroupType = () => {
return getLocalStorage(LOCALSTORAGE_GROUP_TYPE) || '';
}

export const setLocalGroupType = (value) => {
setLocalStorage(LOCALSTORAGE_GROUP_TYPE, value);
}

export const getLocalGroupName = () => {
return getLocalStorage(LOCALSTORAGE_GROUP_NAME) || '';
}

export const setLocalGroupName = (value) => {
setLocalStorage(LOCALSTORAGE_GROUP_NAME, value);
}

export const getLocalGroupProperty = () => {
return getLocalStorage(LOCALSTORAGE_GROUP_PROPERTY) || '';
}

export const setLocalGroupProperty = (value) => {
setLocalStorage(LOCALSTORAGE_GROUP_PROPERTY, value);
}

export const getLocalGroupPropertyValue = () => {
return getLocalStorage(LOCALSTORAGE_GROUP_PROPERTY_VALUE) || '';
}

export const setLocalGroupPropertyValue = (value) => {
setLocalStorage(LOCALSTORAGE_GROUP_PROPERTY_VALUE, value);
}
Loading