refactor(tracking): inject space id via templating instead of using cookies

This commit is contained in:
Benedikt Rötsch
2018-02-07 15:21:45 +01:00
committed by Benedikt Rötsch
parent 46074b508d
commit 67dca923e9
3 changed files with 2 additions and 7 deletions

2
app.js
View File

@@ -94,7 +94,7 @@ app.use(catchErrors(async function (request, response, next) {
const space = await getSpace() const space = await getSpace()
// Update credentials in cookie when space connection is successful // Update credentials in cookie when space connection is successful
updateCookie(response, SETTINGS_NAME, settings) updateCookie(response, SETTINGS_NAME, response.locals.settings)
// Get available locales from space // Get available locales from space
response.locals.locales = space.locales response.locals.locales = space.locales

View File

@@ -36,9 +36,6 @@ module.exports = async function settingsMiddleware (request, response, next) {
} }
/* eslint-enable camelcase */ /* eslint-enable camelcase */
// The space id needs to be available in the frontend for our example app
response.cookie('space_id', settings.spaceId)
initClients(settings) initClients(settings)
response.locals.settings = settings response.locals.settings = settings
next() next()

View File

@@ -28,12 +28,10 @@ script(async).
snowplow('enableLinkClickTracking') snowplow('enableLinkClickTracking')
const space_id = decodeURIComponent(document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*" + encodeURIComponent('space_id').replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=\\s*([^;]*).*$)|^.*$"), "$1")) || null;
snowplow('trackSelfDescribingEvent', { snowplow('trackSelfDescribingEvent', {
schema: 'iglu:com.contentful/app_the_example_app_open/jsonschema/1-0-0', schema: 'iglu:com.contentful/app_the_example_app_open/jsonschema/1-0-0',
data: { data: {
space_id, space_id: '#{settings.spaceId}',
sdk_language_used: 'javascript', sdk_language_used: 'javascript',
app_framework: 'nodejs' app_framework: 'nodejs'
} }