Skip to content

Commit

Permalink
Add button to open page in new tab
Browse files Browse the repository at this point in the history
  • Loading branch information
sviik committed Mar 14, 2024
1 parent 6df791a commit 9cb7718
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions index.htm
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ <h2>Update visitor information</h2>
<textarea id="updateInformation" rows="10" cols="50"></textarea>
<button onclick="onUpdateInformation('replace')">Replace</button>
<button onclick="onUpdateInformation('merge')">Merge</button>

<h2>Other</h2>
<a onclick="openNewTab()">Open new tab</a>
</div>
</body>
</html>
15 changes: 14 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@

const openNewTab = () => {
const loc = window.location;
const href = `https://${loc.host}/${loc.pathname}?color=white`;
window.open(href, '_blank').focus();
};

const maybeSetBackgroundColor = () => {
const urlParams = new URLSearchParams(window.location.search);
const color = urlParams.get('color');
if (color) document.body.style.backgroundColor = color;
};

const setInfoValue = (elementId, value) => {
const element = document.getElementById(elementId);
element.innerText = value;
Expand Down Expand Up @@ -40,6 +52,8 @@ const defaultVisitorInformation = `{
}`;

const boot = () => {
maybeSetBackgroundColor();

copyElementTextOnClick('siteId');
copyElementTextOnClick('visitorId');
copyElementTextOnClick('engagementId');
Expand All @@ -48,7 +62,6 @@ const boot = () => {
copyOnClick('accessToken', () => sm.accessToken)
document.getElementById('updateInformation').value = defaultVisitorInformation;


sm.getApi({version: 'v1'}).then(glia => {
setInfoValue('siteId', glia.getSiteId());
setInfoValue('visitorId', glia.getVisitorId());
Expand Down

0 comments on commit 9cb7718

Please sign in to comment.