# Embed JS in a post

**URL:** https://meta.discourse.org/t/embed-js-in-a-post/233751
**Category:** Marketplace
**Created:** [July 23, 2022, 4:05pm UTC](https://meta.discourse.org/t/embed-js-in-a-post/233751 "2022-07-23T16:05:10Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![VincentAlse](https://avatars.discourse-cdn.com/v4/letter/v/7ba0ec/32.png) [@VincentAlse](https://meta.discourse.org/u/VincentAlse)
#### Post date: [July 23, 2022, 4:05pm UTC](https://meta.discourse.org/t/embed-js-in-a-post/233751/1 "2022-07-23T16:05:10Z")

</div>

Hi All,

I’m looking for a developer to help embed Google Analytics into a post.

The GA embed API provides the script. Just need to make it work in a post.

> **[Google Analytics  |  Google for Developers](https://developers.google.com/analytics/legacy/universal-analytics)**

Example code:

```plaintext
<!DOCTYPE html>
<html>
<head>
  <title>Embed API Demo</title>
</head>
<body>

<!-- Step 1: Create the containing elements. -->

<section id="auth-button"></section>
<section id="view-selector"></section>
<section id="timeline"></section>

<!-- Step 2: Load the library. -->

<script>
(function(w,d,s,g,js,fjs){
  g=w.gapi||(w.gapi={});g.analytics={q:[],ready:function(cb){this.q.push(cb)}};
  js=d.createElement(s);fjs=d.getElementsByTagName(s)[0];
  js.src='https://apis.google.com/js/platform.js';
  fjs.parentNode.insertBefore(js,fjs);js.onload=function(){g.load('analytics')};
}(window,document,'script'));
</script>
<script>
gapi.analytics.ready(function() {

  // Step 3: Authorize the user.

  var CLIENT_ID = 'Insert your client ID here';

  gapi.analytics.auth.authorize({
    container: 'auth-button',
    clientid: CLIENT_ID,
  });

  // Step 4: Create the view selector.

  var viewSelector = new gapi.analytics.ViewSelector({
    container: 'view-selector'
  });

  // Step 5: Create the timeline chart.

  var timeline = new gapi.analytics.googleCharts.DataChart({
    reportType: 'ga',
    query: {
      'dimensions': 'ga:date',
      'metrics': 'ga:sessions',
      'start-date': '30daysAgo',
      'end-date': 'yesterday',
    },
    chart: {
      type: 'LINE',
      container: 'timeline'
    }
  });

  // Step 6: Hook up the components to work together.

  gapi.analytics.auth.on('success', function(response) {
    viewSelector.execute();
  });

  viewSelector.on('change', function(ids) {
    var newIds = {
      query: {
        ids: ids
      }
    }
    timeline.set(newIds).execute();
  });
});
</script>
</body>
</html>

```

---

<div class="post-metadata">

### Author: ![Ahmed\_Gagan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ahmed_gagan/32/161985_2.png) [@Ahmed\_Gagan](https://meta.discourse.org/u/Ahmed_Gagan)
#### Post date: [July 23, 2022, 4:50pm UTC](https://meta.discourse.org/t/embed-js-in-a-post/233751/2 "2022-07-23T16:50:35Z")

</div>

Hi @VincentAlse  
I am interested to take this up, sending you a PM

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [August 22, 2022, 4:51pm UTC](https://meta.discourse.org/t/embed-js-in-a-post/233751/3 "2022-08-22T16:51:20Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
