Skip to content

Commit

Permalink
Merge pull request #55 from rtCamp/fix/chips-demo
Browse files Browse the repository at this point in the history
Streamline CHIPS demo
  • Loading branch information
gagan0123 committed Feb 26, 2024
2 parents a3fdf19 + a3063f1 commit 50f6cf8
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 19 deletions.
3 changes: 1 addition & 2 deletions src/demos/chips/analytics-first-party.ejs
@@ -1,13 +1,12 @@
<%- include(commonPath + '/header.ejs') %>

<%- include(commonPath + '/internal-page/header.ejs') %>
<p class="text-center">Track user interactions using the analytics code provided below:</p>
<div class="flex justify-center space-x-4 mt-4">
<button onclick="trackInteraction('buttonClicked')" class="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-700 transition duration-300">
Track me!
</button>
<button onclick="trackInteraction('buttonClickedCHIPS')" class="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-700 transition duration-300">
CHIPS Track me!
Track me! (CHIPS)
</button>
</div>
<div id="status" class="text-center mt-4"></div>
Expand Down
4 changes: 1 addition & 3 deletions src/demos/chips/analytics-third-party.ejs
@@ -1,14 +1,12 @@
<%- include(commonPath + '/header.ejs') %>

<%- include(commonPath + '/internal-page/header.ejs') %>
<p class="text-center">Track user interactions using the analytics code provided below:</p>

<div class="flex justify-center space-x-4 mt-4">
<button onclick="trackInteraction('buttonClicked')" class="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-700 transition duration-300">
Track me!
</button>
<button onclick="trackInteraction('buttonClickedCHIPS')" class="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-700 transition duration-300">
CHIPS Track me!
Track me! (CHIPS)
</button>
</div>
<div id="status" class="text-center mt-4"></div>
Expand Down
2 changes: 1 addition & 1 deletion src/demos/chips/analytics.ejs
Expand Up @@ -22,7 +22,7 @@
} ).then( function ( data ) {
var statusDiv = document.getElementById( 'status' );
if ( statusDiv ) {
statusDiv.textContent = 'Interaction tracked for ID : ' + data;
statusDiv.textContent = 'Interaction tracked!';
statusDiv.style.color = 'green';
}
} ).catch( function ( error ) {
Expand Down
20 changes: 8 additions & 12 deletions src/demos/chips/routes.js
Expand Up @@ -5,19 +5,15 @@ const uuid = require( 'uuid' );

router.get('/', (req, res) => {
// Send the default page
res.render(path.join(__dirname,'index'), {
res.render(path.join(__dirname,'analytics-third-party'), {
title: 'CHIPS'
});
});
router.get('/analytics-first-party', (req, res) => {
res.render(path.join(__dirname,'analytics-first-party'), {
title: 'First Party Cookie Experiments'
});
});

router.get('/analytics-third-party', (req, res) => {
// Send the default page
res.render(path.join(__dirname,'analytics-third-party'), {
title: 'Third Party Cookie Experiments'
title: 'CHIPS'
});
});
// Serve the analytics.js file to the site
Expand All @@ -39,16 +35,16 @@ router.get( '/analytics.js', ( req, res ) => {

}

let analyticsIdCHIPS = req.cookies['__Host-analyticsId-chips'];
let analyticsIdCHIPS = req.cookies['analyticsId-chips'];

if ( !analyticsIdCHIPS ) {
analyticsIdCHIPS = uuid.v4();
let expire = 30 * 24 * 60 * 60 * 1000;
res.append(
/*res.append(
'Set-Cookie', '__Host-analyticsId-chips=' + analyticsIdCHIPS + '; Max-Age=' + expire + '; HttpOnly; Secure; Path=/; SameSite=None; Partitioned;'
);
);*/
res.append(
'Set-Cookie', 'analyticsId-chips-test=' + analyticsIdCHIPS + ';Domain='+res.locals.domainC+'; Max-Age=' + expire + '; HttpOnly; Secure; Path=/; SameSite=None; Partitioned;'
'Set-Cookie', 'analyticsId-chips=' + analyticsIdCHIPS + ';Domain='+res.locals.domainC+'; Max-Age=' + expire + '; HttpOnly; Secure; Path=/; SameSite=None; Partitioned;'
);
}

Expand All @@ -73,7 +69,7 @@ router.post( '/track', ( req, res ) => {

router.post( '/trackCHIPS', ( req, res ) => {
const {interaction} = req.body;
const analyticsIdCHIPS = req.cookies['__Host-analyticsId-chips'];
const analyticsIdCHIPS = req.cookies['analyticsId-chips'];

if ( interaction && analyticsIdCHIPS ) {

Expand Down
1 change: 0 additions & 1 deletion src/scenarios/analytics/index.ejs
@@ -1,7 +1,6 @@
<%- include(commonPath + '/header.ejs') %>

<%- include(commonPath + '/internal-page/header.ejs') %>
<p class="text-lg mb-4 text-center">Here is a button that tracks clicks using a third-party analytics service; check if it works.</p>

<div class="flex justify-center space-x-4 my-10">
<button onclick="trackInteraction('buttonClicked')" class="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-700 transition duration-300">
Expand Down

0 comments on commit 50f6cf8

Please sign in to comment.