mardi 23 février 2016

Dynamically populate google_tag_params on document ready

I am using google_tag_params for Adwords. I am trying to set it after the page has loaded because the value I want is not introduced until an Ember component has rendered.

<script type="text/javascript">
var topicCategory = '';
console.log("1");
var topicView =  require('discourse/views/topic').default;

 topicView.reopen({

      didInsertElement : function(){
        this._super();
        console.log("2");
        topicCategory = this._controller.model.category.name;
      }
});
$(function() {
    console.log("3");
    var google_tag_params = {
        category: topicCategory
    }
});
</script>

google_tag_params is not picked up in the above code, but the console.logs run correctly (1,2,3). I remove the document on ready, google_tag_params is recognized, but the console.logs run out of order (1,3,2).




Aucun commentaire:

Enregistrer un commentaire