From b99c5428d027608cdf44cd39e37298272812baf6 Mon Sep 17 00:00:00 2001 From: Rishabh Garg Date: Wed, 21 Sep 2022 19:01:36 +0530 Subject: [PATCH] Added referrer attribution columns to events table (#15436) refs TryGhost/Team#1931 - referrer source, medium and url will be stored in the events table along with rest of attribution data - stores referrer information on two tables - `members_created_events` for signups - `members_subscription_created_events` for paid conversions --- ...referrer-columns-to-member-events-table.js | 21 +++++++++++++++++++ ...er-columns-to-subscription-events-table.js | 21 +++++++++++++++++++ ghost/core/core/server/data/schema/schema.js | 8 ++++++- .../admin/__snapshots__/members.test.js.snap | 4 ++-- .../__snapshots__/webhooks.test.js.snap | 2 +- .../unit/server/data/schema/integrity.test.js | 2 +- 6 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 ghost/core/core/server/data/migrations/versions/5.16/2022-09-19-17-44-add-referrer-columns-to-member-events-table.js create mode 100644 ghost/core/core/server/data/migrations/versions/5.16/2022-09-19-17-44-add-referrer-columns-to-subscription-events-table.js diff --git a/ghost/core/core/server/data/migrations/versions/5.16/2022-09-19-17-44-add-referrer-columns-to-member-events-table.js b/ghost/core/core/server/data/migrations/versions/5.16/2022-09-19-17-44-add-referrer-columns-to-member-events-table.js new file mode 100644 index 0000000000..8480cb9aec --- /dev/null +++ b/ghost/core/core/server/data/migrations/versions/5.16/2022-09-19-17-44-add-referrer-columns-to-member-events-table.js @@ -0,0 +1,21 @@ +const {createAddColumnMigration, combineNonTransactionalMigrations} = require('../../utils'); + +module.exports = combineNonTransactionalMigrations( + createAddColumnMigration('members_created_events', 'referrer_source', { + type: 'string', + maxlength: 191, + nullable: true + }), + + createAddColumnMigration('members_created_events', 'referrer_medium', { + type: 'string', + maxlength: 191, + nullable: true + }), + + createAddColumnMigration('members_created_events', 'referrer_url', { + type: 'string', + maxlength: 2000, + nullable: true + }) +); diff --git a/ghost/core/core/server/data/migrations/versions/5.16/2022-09-19-17-44-add-referrer-columns-to-subscription-events-table.js b/ghost/core/core/server/data/migrations/versions/5.16/2022-09-19-17-44-add-referrer-columns-to-subscription-events-table.js new file mode 100644 index 0000000000..06812500f1 --- /dev/null +++ b/ghost/core/core/server/data/migrations/versions/5.16/2022-09-19-17-44-add-referrer-columns-to-subscription-events-table.js @@ -0,0 +1,21 @@ +const {createAddColumnMigration, combineNonTransactionalMigrations} = require('../../utils'); + +module.exports = combineNonTransactionalMigrations( + createAddColumnMigration('members_subscription_created_events', 'referrer_source', { + type: 'string', + maxlength: 191, + nullable: true + }), + + createAddColumnMigration('members_subscription_created_events', 'referrer_medium', { + type: 'string', + maxlength: 191, + nullable: true + }), + + createAddColumnMigration('members_subscription_created_events', 'referrer_url', { + type: 'string', + maxlength: 2000, + nullable: true + }) +); diff --git a/ghost/core/core/server/data/schema/schema.js b/ghost/core/core/server/data/schema/schema.js index 43035aeae3..fde4880bb6 100644 --- a/ghost/core/core/server/data/schema/schema.js +++ b/ghost/core/core/server/data/schema/schema.js @@ -497,6 +497,9 @@ module.exports = { } }, attribution_url: {type: 'string', maxlength: 2000, nullable: true}, + referrer_source: {type: 'string', maxlength: 191, nullable: true}, + referrer_medium: {type: 'string', maxlength: 191, nullable: true}, + referrer_url: {type: 'string', maxlength: 2000, nullable: true}, source: { type: 'string', maxlength: 50, nullable: false, validations: { isIn: [['member', 'import', 'system', 'api', 'admin']] @@ -634,7 +637,10 @@ module.exports = { isIn: [['url', 'post', 'page', 'author', 'tag']] } }, - attribution_url: {type: 'string', maxlength: 2000, nullable: true} + attribution_url: {type: 'string', maxlength: 2000, nullable: true}, + referrer_source: {type: 'string', maxlength: 191, nullable: true}, + referrer_medium: {type: 'string', maxlength: 191, nullable: true}, + referrer_url: {type: 'string', maxlength: 2000, nullable: true} }, offer_redemptions: { id: {type: 'string', maxlength: 24, nullable: false, primary: true}, diff --git a/ghost/core/test/e2e-api/admin/__snapshots__/members.test.js.snap b/ghost/core/test/e2e-api/admin/__snapshots__/members.test.js.snap index a24e700ece..775b594856 100644 --- a/ghost/core/test/e2e-api/admin/__snapshots__/members.test.js.snap +++ b/ghost/core/test/e2e-api/admin/__snapshots__/members.test.js.snap @@ -266,7 +266,7 @@ exports[`Members API - member attribution Returns sign up attributions in activi Object { "access-control-allow-origin": "http://127.0.0.1:2369", "cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0", - "content-length": "8544", + "content-length": "8874", "content-type": "application/json; charset=utf-8", "etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/, "vary": "Origin, Accept-Encoding", @@ -3546,7 +3546,7 @@ exports[`Members API Can subscribe to a newsletter 5: [headers] 1`] = ` Object { "access-control-allow-origin": "http://127.0.0.1:2369", "cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0", - "content-length": "4756", + "content-length": "4822", "content-type": "application/json; charset=utf-8", "etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/, "vary": "Origin, Accept-Encoding", diff --git a/ghost/core/test/e2e-api/members/__snapshots__/webhooks.test.js.snap b/ghost/core/test/e2e-api/members/__snapshots__/webhooks.test.js.snap index af833ecc26..ce65d04441 100644 --- a/ghost/core/test/e2e-api/members/__snapshots__/webhooks.test.js.snap +++ b/ghost/core/test/e2e-api/members/__snapshots__/webhooks.test.js.snap @@ -421,7 +421,7 @@ exports[`Members API Member attribution Returns subscription created attribution Object { "access-control-allow-origin": "http://127.0.0.1:2369", "cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0", - "content-length": "13578", + "content-length": "14106", "content-type": "application/json; charset=utf-8", "etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/, "vary": "Origin, Accept-Encoding", diff --git a/ghost/core/test/unit/server/data/schema/integrity.test.js b/ghost/core/test/unit/server/data/schema/integrity.test.js index 872b08a880..51c75ca37f 100644 --- a/ghost/core/test/unit/server/data/schema/integrity.test.js +++ b/ghost/core/test/unit/server/data/schema/integrity.test.js @@ -35,7 +35,7 @@ const validateRouteSettings = require('../../../../../core/server/services/route */ describe('DB version integrity', function () { // Only these variables should need updating - const currentSchemaHash = 'dbff9c0145b92f7c6b18af1029b8fe7e'; + const currentSchemaHash = '999d625400e6d87efe0fd66e6bda4059'; const currentFixturesHash = '8cf221f0ed930ac1fe8030a58e60d64b'; const currentSettingsHash = '2978a5684a2d5fcf089f61f5d368a0c0'; const currentRoutesHash = '3d180d52c663d173a6be791ef411ed01';