Skip to content

Commit

Permalink
Aut 1556 - Advanced TMX profiling (#49)
Browse files Browse the repository at this point in the history
* [AUT-1556] - Advanced Profiling

* [AUT-1556] - Advanced TMX profiling
  • Loading branch information
justinsoong committed Feb 7, 2024
1 parent 7635cc6 commit fcdbf3b
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion src/authsignal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@ import {
TokenPayload,
WindowLaunchOptions,
} from "./types";
import {PopupHandler, WindowHandler} from "./handlers";
import {Passkey} from "./passkey";
import {PopupHandler, WindowHandler} from "./handlers";

const DEFAULT_COOKIE_NAME = "__as_aid";
const DEFAULT_PROFILING_COOKIE_NAME = "__as_pid";

const DEFAULT_BASE_URL = "https://api.authsignal.com/v1";

const TMX_ORG_ID = "4a08uqve";

export class Authsignal {
anonymousId = "";
profilingId = "";
cookieDomain = "";
anonymousIdCookieName = "";
passkey: Passkey;
Expand Down Expand Up @@ -72,6 +76,46 @@ export class Authsignal {
}
}

initAdvancedProfiling(baseUrl?: string): undefined {
const profilingId = uuidv4();
this.profilingId = profilingId;
setCookie({
name: DEFAULT_PROFILING_COOKIE_NAME,
value: profilingId,
expire: Infinity,
domain: this.cookieDomain,
secure: document.location.protocol !== "http:",
});

const tmxProfilingScruiptUrl = baseUrl
? `${baseUrl}/fp/tags.js?org_id=${TMX_ORG_ID}&session_id=${profilingId}`
: `https://h.online-metrix.net/fp/tags.js?org_id=${TMX_ORG_ID}&session_id=${profilingId}`;
const script = document.createElement("script");
script.src = tmxProfilingScruiptUrl;
script.async = false;
script.id = "as_adv_profile";
document.head.appendChild(script);

const pixelContainer = document.createElement("noscript");
pixelContainer.setAttribute("id", "as_adv_profile_pixel");
pixelContainer.setAttribute("aria-hidden", "true");

// Instantiate Pixel
const iframe = document.createElement("iframe");
const profilingPixelUrl = baseUrl
? `${baseUrl}/fp/tags?org_id=${TMX_ORG_ID}&session_id=${profilingId}`
: `https://h.online-metrix.net/fp/tags?org_id=${TMX_ORG_ID}&session_id=${profilingId}`;

iframe.setAttribute("id", "as_adv_profile_pixel");
iframe.setAttribute("src", profilingPixelUrl);
iframe.setAttribute("style", "width: 100px; height: 100px; border: 0; position: absolute; top: -5000px;");

if (pixelContainer) {
pixelContainer.appendChild(iframe);
document.body.prepend(pixelContainer);
}
}

private launchWithRedirect(url: string) {
window.location.href = url;
}
Expand Down

0 comments on commit fcdbf3b

Please sign in to comment.