Skip to content

Commit

Permalink
Correct formatting in analytics.ejs files
Browse files Browse the repository at this point in the history
  • Loading branch information
gagan0123 committed Oct 5, 2023
1 parent 60cc938 commit 9dcd26b
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 72 deletions.
77 changes: 39 additions & 38 deletions demos/chips/analytics.ejs
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
<% // views/analytics.ejs %>
(function(window) {
// Track user interactions
function trackInteraction(interaction) {
if('buttonClickedCHIPS' === interaction ){
var remoteURL = '<%= protocol %>://<%= domainC %><% if (isPortPresent) { %>:<%= port %><% } %>/chips/trackCHIPS';
} else {
var remoteURL = '<%= protocol %>://<%= domainC %><% if (isPortPresent) { %>:<%= port %><% } %>/chips/track';
}
fetch(remoteURL, {
method: 'POST',
credentials: 'include',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({interaction: interaction})
}).then(function(response) {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.text();
}).then(function(data) {
var statusDiv = document.getElementById('status');
if (statusDiv) {
statusDiv.textContent = 'Interaction tracked for ID : ' + data;
statusDiv.style.color = 'green';
}
}).catch(function(error) {
var statusDiv = document.getElementById('status');
if (statusDiv) {
statusDiv.textContent = 'Interaction could not be tracked.';
statusDiv.style.color = 'red';
}
});
}
(
function ( window ) {
// Track user interactions
function trackInteraction( interaction ) {
if ( 'buttonClickedCHIPS' === interaction ) {
var remoteURL = '<%= protocol %>://<%= domainC %><% if (isPortPresent) { %>:<%= port %><% } %>/chips/trackCHIPS';
} else {
var remoteURL = '<%= protocol %>://<%= domainC %><% if (isPortPresent) { %>:<%= port %><% } %>/chips/track';
}
fetch( remoteURL, {
method: 'POST',
credentials: 'include',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify( {interaction: interaction} )
} ).then( function ( response ) {
if ( !response.ok ) {
throw new Error( 'Network response was not ok' );
}
return response.text();
} ).then( function ( data ) {
var statusDiv = document.getElementById( 'status' );
if ( statusDiv ) {
statusDiv.textContent = 'Interaction tracked for ID : ' + data;
statusDiv.style.color = 'green';
}
} ).catch( function ( error ) {
var statusDiv = document.getElementById( 'status' );
if ( statusDiv ) {
statusDiv.textContent = 'Interaction could not be tracked.';
statusDiv.style.color = 'red';
}
} );
}

// Expose the trackInteraction function globally
window.trackInteraction = trackInteraction;
})(window);
// Expose the trackInteraction function globally
window.trackInteraction = trackInteraction;
}
)( window );
69 changes: 35 additions & 34 deletions scenarios/analytics/analytics.ejs
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
<% // views/analytics.ejs %>
(function(window) {
// Track user interactions
function trackInteraction(interaction) {
var remoteURL = '<%= protocol %>://<%= domainC %><% if (isPortPresent) { %>:<%= port %><% } %>/analytics/track';
fetch(remoteURL, {
method: 'POST',
credentials: 'include',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({interaction: interaction})
}).then(function(response) {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.text();
}).then(function(data) {
var statusDiv = document.getElementById('status');
if (statusDiv) {
statusDiv.textContent = 'Interaction tracked for User : ' + data;
statusDiv.style.color = 'green';
}
}).catch(function(error) {
var statusDiv = document.getElementById('status');
if (statusDiv) {
statusDiv.textContent = 'Interaction could not be tracked.';
statusDiv.style.color = 'red';
}
});
}
(
function ( window ) {
// Track user interactions
function trackInteraction( interaction ) {
var remoteURL = '<%= protocol %>://<%= domainC %><% if (isPortPresent) { %>:<%= port %><% } %>/analytics/track';
fetch( remoteURL, {
method: 'POST',
credentials: 'include',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify( {interaction: interaction} )
} ).then( function ( response ) {
if ( !response.ok ) {
throw new Error( 'Network response was not ok' );
}
return response.text();
} ).then( function ( data ) {
var statusDiv = document.getElementById( 'status' );
if ( statusDiv ) {
statusDiv.textContent = 'Interaction tracked for User : ' + data;
statusDiv.style.color = 'green';
}
} ).catch( function ( error ) {
var statusDiv = document.getElementById( 'status' );
if ( statusDiv ) {
statusDiv.textContent = 'Interaction could not be tracked.';
statusDiv.style.color = 'red';
}
} );
}

// Expose the trackInteraction function globally
window.trackInteraction = trackInteraction;
})(window);
// Expose the trackInteraction function globally
window.trackInteraction = trackInteraction;
}
)( window );

0 comments on commit 9dcd26b

Please sign in to comment.