# Est-il possible de passer l'objet JSON postStream initial dans le datalayer GTM ?

**URL:** <https://meta.discourse.org/t/is-it-somehow-possible-to-pass-the-initial-poststream-json-object-into-the-gtm-datalayer/161035>\
**Category:** Development\
**Created:** [Août 16, 2020, 1:50 UTC](https://meta.discourse.org/t/is-it-somehow-possible-to-pass-the-initial-poststream-json-object-into-the-gtm-datalayer/161035 "2020-08-16T13:50:00Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![Terrapop](https://avatars.discourse-cdn.com/v4/letter/t/ecd19e/32.png) [@Terrapop](https://meta.discourse.org/u/Terrapop)\
**Post date:** [Août 16, 2020, 1:50 UTC](https://meta.discourse.org/t/is-it-somehow-possible-to-pass-the-initial-poststream-json-object-into-the-gtm-datalayer/161035/1 "2020-08-16T13:50:00Z")

</div>

Est-il possible de passer l’objet du flux du premier message pour les pages de sujets à la couche de données GTM sans effectuer une autre requête AJAX comme je le fais actuellement, ce qui est une mauvaise solution de contournement ?

```
<script type="text/discourse-plugin" version="0.8">
const currentUser = api.getCurrentUser();
let userId;

if (currentUser) {
    userId = currentUser.id;
}
else
{
    userId = 0;
}

var getJSON = function(url, callback) {
    var xhr = new XMLHttpRequest();
    xhr.open('GET', url, true);
    xhr.responseType = 'json';
    xhr.onload = function() {
      var status = xhr.status;
      if (status === 200) {
        callback(null, xhr.response);
      } else {
        callback(status, xhr.response);
      }
    };
    xhr.send();
};

api.onPageChange((url, title) => {
    if (url.match(/^\/t\//)) {

	    getJSON(url + '.json',
        function(err, data) {
          if (err !== null) {
              
            window.dataLayer.push({
                'event': 'pageChangeData',
                'userId': userId,
                'PageType': 'topic',
                'PageJson': false
            });
            
          } else {
        
            window.dataLayer.push({
                'event': 'pageChangeData',
                'userId': userId,
                'PageType': 'topic',
                'PageJson': data
            });
          }
          
        });
	    
	} else {
	    
	        window.dataLayer.push({
                'event': 'pageChangeData',
                'userId': userId,
                'PageType': 'notopic',
                'PageJson': false
            });
	}

});
</script>

```

---

_[View the full topic](https://meta.discourse.org/t/is-it-somehow-possible-to-pass-the-initial-poststream-json-object-into-the-gtm-datalayer/161035)._
