Trying to inject the Google Analytics ID dynamically into the script. A setup like this where {{configs[0].ga_id}} holds the ID.
<script>
google code....
ga('create', '{{configs[0].ga_id}}', 'auto');
</script>
The above method is not successful. Attempted several alternatives but none are working.
'{configs[0].ga_id}',
'configs[0].ga_id',
+ configs[0].ga_id +
Any other suggestions?
UPDATE: from MarkoCen
Inserted this directive and modified the HTML as follows. While inspecting the element, the ID "UA-XXXXXXXX-1" is displayed correctly, but in console.log of the directive "{{configs[0].ga_id}}" is seen.
<google-analytics id="{{configs[0].ga_id}}"></google-analytics>
app.directive('googleAnalytics', function(){
return {
restrict: 'E',
replace: true,
template: function(elem, attr){
console.log(attr.id);
return "<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', '" + attr.id + "', 'auto');</script>"
}
}
})