A
A
Andrey Okhotnikov2019-04-24 11:07:12
React
Andrey Okhotnikov, 2019-04-24 11:07:12

How to add counter scripts to React pages?

It is necessary to integrate several services into react and react-narive applications. The instructions provide for adding scripts to each page.
For example, the code

<script>(function(w, d, s, p) { var f = d.getElementsByTagName(s)[0], j = d.createElement(s); j.async = true; j.src = '//cdn.rutarget.ru/static/tag/tag.js'; f.parentNode.insertBefore(j, f); w[p] = {rtgNoSync: false, rtgSyncFrame: true}; })(window, document, 'script', '_rtgParams');</script>

And then on some actions call the code
var _rutarget = window._rutarget || [];
_rutarget.push({'event': 'showOffer'});

So what is the right way to implement this in React?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2019-04-24
@tsepen

1. Add a script to the html template to which the application is attached.
2. We initialize an empty array at the entry point:
3. We use it in any part of the application: You can write your own wrapper:

window._rutarget = [];

const AdService = {
  showOffer() {
    window._rutarget.push({'event': 'showOffer'});
  }, 
};

export default AdService;

In React Native, the script tag cannot be used, unless you can try using WebVIew .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question