Go to google analytics
Sign Up in google analytics and fill the useful information. it will generate the javascript code. Copy that javascript code. Now paste that javascript code into the app/views/layouts/application.html.erb just up from the end of the body tag </body>.The given layout is the layout which I am using for all pages.javascript code provided by google analytics(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics.js','ga');ga('create', 'UA-XXXX-XX', 'auto');ga('send', 'pageview');
Most of the application are single page applications so it is necessary to keep track the ajax call also. so create a new file in app/assets/javascripts/ajax_pagetracker.jsCopy the below code into the file(function ($) {$(document).ajaxSend(function(event, xhr, settings){if (typeof ga !== "undefined" && ga !== null) {ga('send', {'hitType': 'pageview','page': settings.url});}});})(jQuery);Note: Keep track the ajax calls via this method is not a better option at all because it will also track the other ajax calls like (loading the assets via ajax, loading the images via ajax). So keep track the images and other calls is not a better option at all. so we include tracking code manually in every ajax. For ex.$.ajax({type : 'get',url : url,data : {"curr_code": currency}}).done(function(){ga('send', {‘hitType': 'pageview', 'page': url });});5. Include that file into the app/assets/javascripts/application.js. If you have used require_tree .than you don’t have need to include the file.//= require ajax_pagetracker6. In rails 4, we also use turbolinks and google analytics doesn’t track the page loaded by the turbolinks so follow the below steps for track the pages.Create a new file in app/assets/javascripts/turbo_pagetracker.jsPaste the below code into the file.$(document).on('page:change', function() {if (typeof ga !== "undefined" && ga !== null) {ga('send', {'hitType': 'pageview','page': window.location.pathname});}});Also Include that file into app/assets/javascripts/application.js if require_tree is not available.7. Now watch tracking of calls on the google analytics real time overview.
Thursday, 29 January 2015
Google analyicts wth Rails
Friday, 17 October 2014
Set up Chef on Ubuntu Machine
Ubuntu + Chef + Errors
On chef server(new ubuntu machine)
cd ~
Install the chef server or install from web site
=> http://www.getchef.com/chef/install/
or
cli
=> wget https://opscode-omnibus-packages.s3.amazonaws.com/ubuntu/12.04/x86_64/chef-server_11.0.10-1.ubuntu.12.04_amd64.deb
Install the package using terminal
=> sudo dpkg -i chef-server*
Run this command to confugre chef server on the machine
=> sudo chef-server-ctl reconfigure
Open browser (write https and ip of server)
https://server_domain_or_IP
Add default username and password.
On workstation(diiferent ubuntu machine)
update the system
=> sudo apt-get update
Install Git
=> sudo apt-get install git
Install Curl
=> sudo apt-get install curl
You can download the chef client from wesite and manually install this.
http://www.getchef.com/chef/install/
otherwise run
=> curl -L https://www.opscode.com/chef/install.sh | sudo bash
Get the chef-repo from git
=> git clone https://github.com/opscode/chef-repo.git
create .chef repository
=> mkdir ~/chef-repo/.chef
Copy the keys:
Now we will put the keys into .chef folder so open in browser put chef server url
https://server_domain_or_IP
Login and Tap on the Clients > edit(chef-validator) > chek the checkbox > save
It will generate a key so just copy the private key and paste in
create a chef-validator file in .chef folder
=> vim chef-validator.pem
paste the key
There should be no extra space
Now same for the Users > admin > edit > check checkbox for regenerate the private key > save
It will generate a key so just copy the private key and paste in
create a chef-validator file in .chef folder
=> vim admin.pem
paste the key
run knife command
=> knife configure --initial
PASTE THE PATH ASKED BY OPETIONS LIKE FOR admin key path should be /home/vagrant/chef-repo/.chef/admnin.pem
same for the all
No need to commit the .chef folder so
=> vim ~/chef-repo/.gitignore
Add .chef in the end of the file
.rake_test_cache
###
# Ignore Chef key files and secrets
###
.chef/*.pem
.chef/encrypted_data_bag_secret
.chef
run knife command to check if knife is configured or not
=> knife user list
if it gives error reconfigure the knife configuration
Client Node (another ubuntu instance) ip address(22.2.22.1)
now bootstrap to the clint using the following command
=> knife bootstrap 22.2.22.1 -x username -P password -N name_for_node --sudo
If bootstraps success than you will find a node in chef-repo/nodes
Now chek client list
=> knife client list
Errors faced by me
While creating node
Error: RuntimeError: Please set EDITOR environment variable
Sol:
export EDITOR=$(which vi)
ERROR: Failed to upload /home/vagrant/chef-repo/cookbooks/apt/recipes/default.rb
Sol:
Chef-server redirects api clients between its components (in this case erchef and bookshelf). These redirects are based on the FQDN of the chef-server. If the server doesn't have a valid FQDN at install time, this can result in redirects to https://localhost:443.
One solution is to fix the FQDN on chef-server and run chef-server-ctl reconfigure.
Another solution is to set a few options in /etc/chef-server/chef-server.rb (I had to create this file) and then run chef-server-ctl reconfigure.
server_name = "192.168.114.11"
api_fqdn server_name
nginx['url'] = "https://#{server_name}"
nginx['server_name'] = server_name
lb['fqdn'] = server_name
bookshelf['vip'] = server_name
Swap Memory in Ubuntu
Swap Memory + Ubuntu
I found these two blogs for swap memory which provide me a good understanding about swap memory and help me to increase swap memory of my Ubuntu system
https://www.digitalocean.com/community/tutorials/how-to-configure-virtual-memory-swap-file-on-a-vps
http://www.garron.me/en/bits/create-add-swap-file-ubuntu.html
Vagrant (Virtual Machine Manager on ubuntu)
Virtual Machine Manager + Vagrant + Generate Multiple VM's + Windows +
Common Errors + VMware
. Create a folder anywhere and give entry in the folder
mkdir tarun
. cd tarun
. vagrant init #it will generate a file named "vagrant" with cinfigurations.
. cd vagrant
. Add a box into the ".vagrant.d\boxes\" in C drive.
. run command :-
vagrant box add precise64 "C:\Users\admin\.vagrant.d\boxes\precise64.box"
. When you will enter into the vagrant folder you will find a vagrant configuration file. In vagrant configuration file create a global configuration for virtual box.
config.vm.box = "precise64"
. Create the three layers.
vagrant up
. Define 3 enviornments with same virtual box.
config.vm.define "web" do |web|
#web.vm.box = "web"
#web.vm.hostname = "web"
web.vm.network :private_network, ip: "192.168.33.10"
web.vm.network :forwarded_port, guest: 80, host: 8080
end
config.vm.define "db" do |db|
#db.vm.box = "db"
#db.vm.hostname = "mysql"
db.vm.network "private_network", ip: "192.168.10.22"
db.vm.network :forwarded_port, guest: 3306, host: 8888
end
config.vm.define "master" do |master|
#master.vm.box = "master"
#master.vm.hostname = "master"
master.vm.network "private_network", ip: "192.168.10.23"
master.vm.network :forwarded_port, guest: 80, host: 8080
end
. Define networks to communicate.
master.vm.network "private_network", ip: "192.168.10.23"
. Define port
master.vm.network :forwarded_port, guest: 80, host: 8080
. After changing run command
vagrant reload #helps to configure the changed configuration
. After generate the three layers, check the virtual box.
. To enter in the layers, use command
vergant ssh web
ERRORS:
Error: Failed to create the host-only adapter :-
Sol: Reinstall the virtualbox and run it as administration.
Or update the virtual box
Error: Vagrant cannot forward the specified ports on this VM, since they
would collide with some other application that is already listening
on these ports. The forwarded port to 8080 is already in use
on the host machine.
Sol: write :- , auto_correct: true
else :- Change the host, if already defined.
Rails and Mysql Set up on ubuntu Server
Ruby + Rails + Mysql + RVM + Gemset + Apache
Steps to set up server
On Ubuntu Image
Reference Link
https://www.digitalocean.com/community/articles/how-to-install-ruby-on-rails-on-ubuntu-12-04-lts-precise-pangolin-with-rvm
1. Install curl first
sudo apt-get install curl
2. Install rvm
\curl -L https://get.rvm.io | bash -s stable
3. Path to load rvm (Given in comments after installation of )
source ~/.rvm/scripts/rvm
or
source ~/.profile
4. Requirements related to rvm
rvm requirements
5. Check version of rubies present on cloud
rvm list known
6. Install specific version
rvm install 1.9.3
7. Create gemset for particular rvm
rvm gemset create demo
8. Use gemset
rvm gemset use demo
9. If you want to build a application from scratch than install gem rails.
gem install rails -v 3.2.14
10. Otherwise enter into the application and run
rvm use 1.9.3-p374@demo
bundle
--------------------------------------------------------------------------------------------------------------------------
Installing Mysql steps
Make sure your package management tools are up-to-date. Also make sure you install all the latest software available.
sudo apt-get update
sudo apt-get dist-upgrade
Install the MySQL server and client packages:
sudo apt-get install mysql-server mysql-client
You need to set a root password
sudo mysqladmin -u root -h localhost password 'mypassword'
sudo mysqladmin -u root -h myhostname password 'mypassword'
For Ruby dependencies install
sudo apt-get install libmysql-ruby
You can now access your MySQL server like this:
mysql -u root -p
--------------------------------------------------------------------------------------------------------------------------
Installing Apache has never been easier using apt-get.
First, I updated the repositories.
sudo apt-get update
Then fixed the locales.
sudo locale-gen en_US en_US.UTF-8 en_CA.UTF-8
sudo dpkg-reconfigure locales
And finally installed all the basic packages I thought I'd need.
sudo apt-get install apache2 curl git build-essential zlibc zlib1g-dev zlib1g libcurl4-openssl-dev libssl-dev libopenssl-ruby apache2-prefork-dev libapr1-dev libaprutil1-dev libreadline6 libreadline6-dev
--------------------------------------------------------------------------------------------------------------------------
Installing Apache has never been easier using apt-get.
First, I updated the repositories.
sudo apt-get update
Then fixed the locales.
sudo locale-gen en_US en_US.UTF-8 en_CA.UTF-8
sudo dpkg-reconfigure locales
And finally installed all the basic packages I thought I'd need.
sudo apt-get install apache2 curl git build-essential zlibc zlib1g-dev zlib1g libcurl4-openssl-dev libssl-dev libopenssl-ruby apache2-prefork-dev libapr1-dev libaprutil1-dev libreadline6 libreadline6-dev
Set Up PostgreSql On Ubuntu
sudo apt-get install postgresql postgresql-contrib
sudo apt-get install libpq-dev
sudo -u postgres createuser --superuser tarun
sudo -u postgres psql
postgres=# \password tarun
password: tarun
enter again password: tarun
\q
Client programs, by default, connect to the local host using your Ubuntu login name and expect to find a database with that name too. So to make things REALLY easy, use your new superuser privileges granted above to create a database with the same name as your login name:
sudo -u postgres createdb tarun
Connecting to your own database to try out some SQL should now be as easy as:
psql
Creating additional database is just as easy, so for example, after running this:
create database mmagap;
If you get the below error after restart the server
sudo apt-get install libpq-dev
sudo -u postgres createuser --superuser tarun
sudo -u postgres psql
postgres=# \password tarun
password: tarun
enter again password: tarun
\q
Client programs, by default, connect to the local host using your Ubuntu login name and expect to find a database with that name too. So to make things REALLY easy, use your new superuser privileges granted above to create a database with the same name as your login name:
sudo -u postgres createdb tarun
Connecting to your own database to try out some SQL should now be as easy as:
psql
Creating additional database is just as easy, so for example, after running this:
create database mmagap;
If you get the below error after restart the server
psql: FATAL: Peer authentication failed for user "postgres"
Switch to postgres user
$ sudo su - postgres #it will ask for password and by default password is also postgres
After switch the user to postgres, open psql console
$ psql
so check the version of postgres if multiple versions are available
psql=# select VERSION();
PostgreSQL 9.1.13 on x86_64-unk.... # so version is 9.1
Now Open From postgres user
vim /etc/postgresql/9.1/main/pg_hba.conf # 9.1 is version return form upper command
and replace
local all postgres peer
to
local all postgres md5
Wowza Server Setup with Ubuntu and Also Integration In Rails
Wowza + Flowplayer + Video Upload + Rails + Video Streaming + Stop video after some time + java setup on ubuntu
$ sudo sh -c 'echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" >> /etc/apt/sources.list'
$ sudo sh -c 'echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" >> /etc/apt/sources.list'
$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EEA14886
$ sudo apt-get update
$ sudo apt-get install oracle-java8-installer
2. Install wowza using (should have account on wowza) :- in browser
http://www.wowza.com/pricing/installer
Copy the secret key of wowza
3. Let it download in directory /home/garg/Downloads/ :- in terminal
cd /home/garg/Downloads/
4. Install wowza
sudo chmod +x WowzaStreamingEngine-4.0.4.deb.bin
sudo ./WowzaStreamingEngine-4.0.4.deb.bin
5. start wowza service :- in terminal
sudo service WowzaStreamingEngine start
// sudo service WowzaStreamingEngine stop
6. On you machine, check wowza is running :- in browser
http://127.0.0.1:1935/
// http://[wowza-ip-address]:1935
7. Start engine manager :- in terminal
sudo service WowzaStreamingEngineManager start
8. In browser
http://127.0.0.1:8088/enginemanager
Read and continue steps and run wowza
Login with user name and password you put in console on wowza installation
Keep flowplayer.content-3.2.9.swf' in assets
--------------------------------------------------------------------------------------------------------------------------
9. Set up amazon S3 on wowza media server
- Click the "Server" tab at the top of the manager, and then select "Media Cache" in the left bar pane.
- Select "Sources" and "Add Media Cache Source"
- Selcect
Source Name = S3 Stream
Source Type = AmazonS3
Aws Key id = "amazon key"
AWS secret = "amazon secret"
Minimum Time To Live:
- select days to keep cache.
- Select "Applications" on top bar of the wowza server.
- Select "VOD Edge" named as "mediacache".
- select "Media Cache Sources", to your amazon "S3 Stream" => created media cache source name of amazon s3.
Add the following settings in code
<script type="text/javascript" src="http://releases.flowplayer.org/js/flowplayer-3.2.13.js"></script>
<%= form_for @taped, :url => upload_taped_video_videos_path, :html => { :multipart => true } do |form| %>
<%= form.file_field :taped_video %>
<%= form.submit "Upload" %>
<% end %><br/>
<%@taped_videos.each_with_index do |tape, i|%>
<div id="videoSection_<%= i %>" style="width:300px;height:300px;"></div>
<div class="cost"><%=tape.cost.to_f%></div>
<div id="replaceLink_<%= i %>" style="display:none">
<% if current_user %>
<%= link_to "Purchase to watch", purchase_taped_video_video_path(tape.id)%>
<% else %>
<!-- <%#= link_to "Already Member?", new_user_session_path%> | <%#= link_to "Register", new_registration_path(resource_name) %> -->
<%= link_to "Already Member?", purchase_taped_video_video_path(tape.id)%> | <%= link_to "Register", "/users/sign_up" %>
<% end %>
</div>
<script type="text/javascript">
$(document).ready(function(){
$("#show-text").hide()
});
flowplayer("videoSection_<%= i %>", "http://releases.flowplayer.org/swf/flowplayer-3.2.18.swf",
{
clip: {
url: "mp4:amazons3/vmh(bucket name on amazon)/file_path/file.mp4",
#url: "<%=File.extname(tape.taped_video_file_name).split('.')[1]%>:amazons3/vmh<%=tape.taped_video.path%>",
autoPlay: false,
autoBuffering: true,
provider: 'rtmp',
onCuepoint: [6000, function(clip, point) {
this.stop()
var plugin = this.getPlugin("content");
plugin.show(10000).setHtml($("#replaceLink_<%= i %>").html());
}]
},
plugins: {
content: {
url: 'flowplayer.content-3.2.9.swf',
display: 'none'
},
rtmp: {
url: '<%= asset_path "flowplayer/flowplayer.rtmp-3.2.13.swf"%>',
netConnectionUrl: 'rtmp://127.0.0.1/mediacache'
}
}
}
);
var player = $f()
player.onLoad(function() {
// this- variable points to the player's API
// this.getScreen().animate({width:300, height:200});
});
</script>
<br/><br/>
<%end%>
Subscribe to:
Posts (Atom)