Skip to content

Commit

Permalink
fix(project): fix lots of things
Browse files Browse the repository at this point in the history
  • Loading branch information
olavoparno committed Aug 11, 2020
1 parent 3b17844 commit 76aabd6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function useHotjar(): TUseHotjar {
const identityHotjar = React.useCallback(
(userId: string, userInfo: string, shouldLog = true): boolean => {
try {
const hotjarIdentityScript = `var userId="${userId}" || null;window.hj("identify",userId,{${userInfo}}});`;
const hotjarIdentityScript = `var userId="${userId}" || null;window.hj("identify",userId,${userInfo});`;
const isIdentified = appendHeadScript({
scriptText: hotjarIdentityScript,
scriptId: 'identity-script',
Expand Down
38 changes: 19 additions & 19 deletions src/useAppendHeadScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,26 @@ type TUseAppendHeadScript = {
};

export function useAppendHeadScript(): TUseAppendHeadScript {
const appendHeadScript = ({
scriptText,
scriptId,
}: TAppendHeadScript): boolean => {
try {
const existentScript = document.getElementById(
scriptId
) as HTMLScriptElement;
const script = existentScript || document.createElement('script');
script.id = scriptId;
script.innerText = scriptText;
script.crossOrigin = 'anonymous';
const appendHeadScript = React.useCallback(
({ scriptText, scriptId }: TAppendHeadScript): boolean => {
try {
const existentScript = document.getElementById(
scriptId
) as HTMLScriptElement;
const script = existentScript || document.createElement('script');
script.id = scriptId;
script.innerText = scriptText;
script.crossOrigin = 'anonymous';

document.head.appendChild(script);
document.head.appendChild(script);

return true;
} catch (error) {
return error;
}
};
return true;
} catch {
return false;
}
},
[]
);

return React.useMemo(() => ({ appendHeadScript }), []);
return React.useMemo(() => ({ appendHeadScript }), [appendHeadScript]);
}

0 comments on commit 76aabd6

Please sign in to comment.