Raymond Camden
Raymond Camden

Reputation: 10857

Using Google Analytics web components, how do I get all of the property IDs?

If you look at the Google Analytics web components, you can see that there is a tag, google-analytics-view-selector, that will automatically create a view control for selecting Analytics properties. But I want access to that data via JS. In other words, how would one get the IDs if they wanted their own control for picking a property? I don't seem to see a property I can hit to fetch this.

Upvotes: 1

Views: 1414

Answers (1)

ebidel
ebidel

Reputation: 24109

This works for me: http://jsbin.com/jojubezu/2/edit

The element exposed .views, .accounts, and .properties that you should be able to use to constructor your own picker.

<style>
  google-analytics-view-selector {
    display: none;
  }
</style>
<google-signin ...></google-signin>

<google-analytics-view-selector
    on-analytics-dashboard-control-change="{{hasIds}}">
</google-analytics-view-selector>
</template>
<script>
  Polymer('my-element', {
    hasIds: function(e, detail, sender) {
      console.log(sender.accounts, sender.views, sender.properties)
    } 
  });
</script>

Upvotes: 3

Related Questions