Analytics
3.7K members online now
3.7K members online now
Dive into multiple domain (Cross/Sub) tracking, implementing Ecommerce and Enhanced Ecommerce, setting up Event tracking, and Universal Analytics code.
 
Guide Me
star_border
Reply

ga('create', 'UA-xxx', 'auto'); working but ga('create', ENV['google_analytics'], 'auto'); not

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

I'm  trying to implement the google analytics tracking code in mine rails app but problem is whenever I used ga('create', 'UA-xxx', 'auto');  its working fine but when i changed tracking code with ENV key like this, ga('create', ENV['google_analytics'], 'auto');  why this is not working? please help.

1 ACCEPTED SOLUTION

Accepted Solutions
Marked as Best Answer.
Solution
Accepted by topic author Vanity C
October 2016

ga('create', 'UA-xxx', 'auto'); working but ga('create', ENV['google_analytics'], 'auto'); not

Follower ✭ ✭ ☆
# 7
Follower ✭ ✭ ☆

Hi Vaniry

 

It is ENV variable is not expanded to value.
The file extension is erb?
If erb file, please try following code.

ga('create', '<%= ENV['google_analytics'] %>', 'auto');

Otherwise, I recommend that you looking for similar source code such as use ENV variable from neaby.
And please try to imitate.

 

 

Thanks Ryota.

View solution in original post

Re: ga('create', 'UA-xxx', 'auto'); working but ga('create', ENV['google_analytics'], 'auto'); not

Follower ✭ ✭ ☆
# 2
Follower ✭ ✭ ☆

Hi Vanity

 

ENV object is variable of Ruby? Or is variable of JavaScript?

If ENV is variable of Ruby, there is a need to be modified to output the value.

 

example: 

 

puts "ga('create', '#{ENV[google_analytics]}', 'auto');"

ga('create', 'UA-xxx', 'auto'); working but ga('create', ENV['google_analytics'], 'auto'); not

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

ohhh my bad, let me try this solution.

 

ga('create', 'UA-xxx', 'auto'); working but ga('create', ENV['google_analytics'], 'auto'); not

Visitor ✭ ✭ ✭
# 4
Visitor ✭ ✭ ✭

Hey Yamda thanks for your valuable response i tried your solution but still not working 

 

ga('create', 'UA-xxx', 'auto'); working but ga('create', ENV['google_analytics'], 'auto'); not

Follower ✭ ✭ ☆
# 5
Follower ✭ ✭ ☆

Hi Vanity

 

Ummm. What is the output HTML code?

The HTML code has following code?

ga('create', 'UA-0000000-1', 'auto');

ga('create', 'UA-xxx', 'auto'); working but ga('create', ENV['google_analytics'], 'auto'); not

Visitor ✭ ✭ ✭
# 6
Visitor ✭ ✭ ✭

<script>
(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','https://www.google-analytics.com/analytics.js','ga');

ga('create', "#{ENV['google_analytics']}", 'auto');
ga('send', 'pageview');

</script>

this is mine full code.

Marked as Best Answer.
Solution
Accepted by topic author Vanity C
October 2016

ga('create', 'UA-xxx', 'auto'); working but ga('create', ENV['google_analytics'], 'auto'); not

Follower ✭ ✭ ☆
# 7
Follower ✭ ✭ ☆

Hi Vaniry

 

It is ENV variable is not expanded to value.
The file extension is erb?
If erb file, please try following code.

ga('create', '<%= ENV['google_analytics'] %>', 'auto');

Otherwise, I recommend that you looking for similar source code such as use ENV variable from neaby.
And please try to imitate.

 

 

Thanks Ryota.

ga('create', 'UA-xxx', 'auto'); working but ga('create', ENV['google_analytics'], 'auto'); not

Visitor ✭ ✭ ✭
# 8
Visitor ✭ ✭ ✭

Thank you so much Ryota :-)