I have faced a problem that I can't understand. Can anyone please help me?
I want to add Google-Analytics metrics to my small project app. I have added gtag script, rails encrypted credentials and set up on Heroku.
It works and tracks when I put my UA manually like that:
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-18929....-2"></script>
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
Then when I run in terminal:
EDITOR="subl --wait" bin/rails credentials:edit
I have added credentials this way:
google_analytics:
google_analytics: UA-18929....-2
When I run the dig command in terminal to see the credentials in rails console it works:
Rails.application.credentials.dig(:google_analytics, :google_analytics)
But then when I replace
=UA-18929....-2"
with
<%= Rails.application.credentials.dig(:google_analytics, :google_analytics) %>
the Google Analytics do not update data. Can please anyone tell me why and how to set it up correctly?
I run both of them locally and when I hardcore my UA it works, when I dig the credentials it doesn't.
I have also tried to print my credentials this way in view:
<%= Rails.application.credentials.as_json %>
and I'm getting empty hash back, it shouldn't work that way I guess.