0.0
The project is in a healthy, maintained state
Allow save UTM tags into database
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
 Dependencies

Development

~> 0.13
~> 3.10.0
 Project Readme

UtmTracker

This gem allow to save UTM tags into your Rails app. UtmTracker allows you to save in the user object with which advertisement he was registered.

Requirements

  • Ruby 2.7.1
  • Rails 6.1.x

Installation

Add this line to your application's Gemfile:

gem 'utm_tracker'

And then execute:

$ bundle install

Usage for Rails

  1. You need to generate Rails migration and add utm_data into your User model for UTM-tags:

$ rails g migration add_utm_data_to_users utm_data:jsonb

and add not null and default modificators into rails migrations:

def change
  add_column :users, :utm_data, :jsonb, null: false, default: {}
end

and then:

$ rails db:migrate

  1. Prepare link into user registration controller:

$ https://example.com?utm[source]=google&utm[medium]=cpc&utm[campaign]=testcampaign&utm[content]={adgroupid}&utm[term]={keyword}

  1. Add into ApplicationController next helper for save utm_tags into current_user session:
class ApplicationController < ActionController::Base
  include UtmTracker::Helper
end
  1. After that, you can use callback into your controllers for get utm data in current user session:
before_action :get_utm_data

Add this callback where you plan to receive advertising traffic.

  1. Into user registration controller add UtmTracker client after save user and put user object and session[:utm]:
@utm = UtmTracker::Client.new(@user, session[:utm])
@utm.call

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/alexlev1/utm_tracker.