discourse/plugins/discourse-adplugin/db/migrate/20251104121942_create_ad_analytics_tables.rb
Juan David Martínez Cubillos cc7f4743a5
FEATURE: Implement ad impressions tracking (#35797)
**Description**

This PR implements these features:
 - Impressions tracking for HouseAds and External Ads
 - Click tracking for HouseAds and External Ads
- Reports of HouseAds performance, ad impressions by user, general ad
impressions, conversion reports by ad and placement, conversion reports
by ad type, and conversion reports by placement.

As part of implementing these features, the HouseAd model had to be
pulled out of the Plugin rows table into its own table. Refactoring had
to be done to account for these changes.

---------

Co-authored-by: Bannon Tanner <bannon.n.tanner@gmail.com>
2025-12-01 12:17:25 -05:00

25 lines
864 B
Ruby

# frozen_string_literal: true
class CreateAdAnalyticsTables < ActiveRecord::Migration[7.0]
def change
create_table :ad_plugin_impressions do |t|
t.integer :ad_type, null: false
t.bigint :ad_plugin_house_ad_id
t.string :placement, null: false
t.integer :user_id
t.timestamps
end
add_index :ad_plugin_impressions, :ad_type
add_index :ad_plugin_impressions, :ad_plugin_house_ad_id
add_index :ad_plugin_impressions, :user_id
add_index :ad_plugin_impressions, %i[ad_type placement]
add_index :ad_plugin_impressions, :created_at
add_foreign_key :ad_plugin_impressions,
:ad_plugin_house_ads,
column: :ad_plugin_house_ad_id,
on_delete: :cascade
add_foreign_key :ad_plugin_impressions, :users, column: :user_id, on_delete: :nullify
end
end