I'm using Low-code platform based on Flutter to develop my app and that platform have Built-in widgets such as (WebView widget "accepts URL") and planning to use it to display Tradingview Widgets
Platform
The widget
singalticker.html Code
<!-- TradingView Widget BEGIN -->
<div class="tradingview-widget-container">
<div class="tradingview-widget-container__widget"></div>
<div class="tradingview-widget-copyright"><span class="blue-text">EURUSD Rates</span> by TradingView</div>
<script type="text/javascript" src="https://s3.tradingview.com/external-embedding/embed-widget-single-quote.js" async>
{
"symbol": "FX:EURUSD",
"width": 350,
"colorTheme": "light",
"isTransparent": false,
"locale": "en"
}
</script>
</div>
<!-- TradingView Widget END -->
So, I've managed to create a html page in GitHub and publish it and then placed its URL in the WebView and its works BUT what I'm asking is how to pass a value through the URL to change the pair
"symbol": "FX:EURUSD",
so when the user choose a pair of (Stock/Fiat) the html page changes depends on that ?
I've tried following multiple solutions here but nothing works !
Any help in this matter will be appreciated thanks
With this you can get query variable from URL string;
// add this function in your page script
function GetQueryVar(variable) {
var query = window.location.search.substring(1)
var vars = query.split('&')
for (var i = 0; i < vars.length; i++) {
var qPair = vars[i].split('=');
if (decodeURIComponent(qPair[0]).toLowerCase() == variable.toLowerCase())
return decodeURIComponent(qPair[1]);
}
}
How to use:
// url is: https://siteurl.com/page?fx=EURUSD
const fx = GetQueryVar('FX') // fx == 'EURUSD'
UPDATE 1
<body>
<div class="tradingview-widget-container">
<div class="tradingview-widget-container__widget"></div>
<div class="tradingview-widget-copyright" id="view"></div>
</div>
<script type="text/javascript">
function getParameterByName(name, url = window.location.href) {
name = name.replace(/[\[\]]/g, '\\$&');
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, ' '));
}
const container = document.getElementById("view")
const symbol = getParameterByName('fx')
document.addEventListener('DOMContentLoaded', function () {
var iframe = document.createElement('iframe')
iframe.setAttribute(
'src',
`https://s.tradingview.com/embed-widget/single-quote#{"width":350,"symbol":"FX:${symbol}","isTransparent":false,"height":126,"utm_source":"","utm_medium":"widget","utm_campaign":"single-quote"}`,
);
iframe.setAttribute('scrolling', 'no')
iframe.setAttribute('allowtransparency', 'true')
iframe.setAttribute('frameborder', 0)
iframe.setAttribute('style', 'box-sizing: border-box; height: calc(94px); width: 350px;')
container.appendChild(iframe)
});
</script>
</div>
</body>
Matomo has stopped tracking page visits for a Rails site of mine that I recently upgraded to use Webpacker.
When I experimentally create a file test.html on a private site and copy/paste the tracking code from my production Rails site to it, tracking does not work either:
!function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"===typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="/packs/",n(n.s=33)}({33:function(e,t){var n,r=window._paq||[];r.push(["setCookieDomain","*.MY_RAILS_SITE"]),r.push(["setDomains",["*.MY_RAILS_SITE","*.MY_RAILS_SITE"]]),r.push(["disableCookies"]),r.push(["trackPageView"]),r.push(["enableLinkTracking"]),function(){var e="https://matomo.MY_MATOMO_HOST/";r.push(["setTrackerUrl",e+"matomo.php"]),r.push(["setSiteId","2"]);var t=document,n=t.createElement("script"),o=t.getElementsByTagName("script")[0];n.type="text/javascript",n.async=!0,n.defer=!0,n.src=e+"matomo.js",o.parentNode.insertBefore(n,o)}(),n=null,addEventListener("turbolinks:load",(function(e){n&&(r.push(["setReferrerUrl",n]),r.push(["setCustomUrl",window.location.href]),r.push(["setDocumentTitle",document.title]),e.data&&e.data.timing&&r.push(["setGenerationTimeMs",e.data.timing.visitEnd-e.data.timing.visitStart]),r.push(["trackPageView"])),n=window.location.href}))}});
However, when I take the script directly from my sources (and not from the production site) and place it into the test.html file, tracking works!
<html>
<head></head>
<body>
<p>Hello</p>
<!-- Matomo -->
<script>
var _paq = window._paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(["setCookieDomain", "*.MY_RAILS_SITE"]);
_paq.push(["setDomains", ["*.MY_RAILS_SITE","*.MY_RAILS_SITE"]]);
_paq.push(["disableCookies"]);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="https://matomo.MY_MATOMO_HOST/";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '2']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
<!-- End Matomo Code -->
</script>
</body>
</html>
(Host names redacted for privacy.)
Evidently, the code gets changed when deploying to production in a way that prevents it from working.
There are no errors in the browser console whatsoever, no trouble with content-security headers etc., and the matomo.js script loads properly, with a HTTP 200 result.
What's going on here?
It seems I have finally gotten it to work again. Looking closely at the JavaScript snippet that Matomo suggests for new sites. I spotted some subtle differences.
- var _paq = window._paq || [];
+ var _paq = window._paq = window._paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(["setCookieDomain", "*.MY_RAILS_SITE"]);
_paq.push(["setDomains", ["*.MY_RAILS_SITE","*.MY_RAILS_SITE"]]);
_paq.push(["disableCookies"]);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="https://matomo.MY_MATOMO_HOST/";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '2']);
var d=document, g=d.createElement('script'),
s=d.getElementsByTagName('script')[0];
- g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
+ g.type='text/javascript'; g.async=true; g.src=u+'matomo.js';
s.parentNode.insertBefore(g,s);
})();
// From https://github.com/turbolinks/turbolinks/issues/436#issuecomment-456862864
// Send Matomo a new event when navigating to a new page using Turbolinks
// (see https://developer.matomo.org/guides/spa-tracking)
(function() {
var previousPageUrl = null;
addEventListener('turbolinks:load', function(event) {
if (previousPageUrl) {
+ var _paq = window._paq = window._paq || [];
_paq.push(['setReferrerUrl', previousPageUrl]);
_paq.push(['setCustomUrl', window.location.href]);
_paq.push(['setDocumentTitle', document.title]);
The _paq variable is assigned differently, and the working snippet is missing the g.defer=true bit. Additionally, _paq is now assigned in the Turbolinks event handler.
I have set up Ad Units and Key Values in DFP. I have built the site with the following code based on Google's tutorials:
<html lang="en">
<head>
<script type="text/javascript">
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
(function() {
var gads = document.createElement("script");
gads.async = true;
gads.type = "text/javascript";
var useSSL = "https:" == document.location.protocol;
gads.src = (useSSL ? "https:" : "http:") + "//www.googletagservices.com/tag/js/gpt.js";
var node =document.getElementsByTagName("script")[0];
node.parentNode.insertBefore(gads, node);
})();
</script>
<script>
var sitePath = "/test-kv/parent/page"
googletag.cmd.push(function() {
var kvAdSlot =
googletag.defineSlot('/00000000' + sitePath, [300, 250], 'kvAd');
kvAdSlot.addService(googletag.pubads());
kvAdSlot.setTargeting('key', 'value');
googletag.pubads().collapseEmptyDivs();
googletag.enableServices();
});
</script>
</head>
<body>
<div id='kvAd'>
<script>
googletag.cmd.push(function() { googletag.display('kvAd'); });
</script>
</div>
</body>
</html>
However, when I test the page, my ROS ads (which have no key values assigned but target all ad units) are showing up. I have been messing with this for a while and cannot figure out why the setTargeting doesn't seem to be working properly to keep non targeted ads out of the key value ad slot.
It's perfectly logical that your ROS ads are returned. Google DFP will not exclude ads based on setTargeting unless specifically defined in your line-item.
In your line-item, if you were to specify that the ROS should be shown IF "key" is not equal to "value", then the ROS ads would not be shown.
I want to use Piwik to trace which user stays on which page in my rails app but I cannot figure out how to trace it. I added a custom variable (page scope) but in Piwik I only see the user_id and its count of visits but not which pages. Also, I got url based view but not for which user. Anybody knows how to deal with this? Also I can not use custom Dimension because my Piwik version is older and I can not upgrade it now. I tried setUserId option as well but no luck.
My code :
<script type="text/javascript">
var _paq = _paq || [];
_paq.push(['setCustomVariable', 1, "user_id", "<%= current_user.id %>", "page" ]);
_paq.push(['setUserId', '<%= current_user.id %>']);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
_paq.push(['enableHeartBeatTimer']);
(function() {
var u="//myserver/piwik/";
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['setSiteId', 1]);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
})();
</script>
<noscript><p><img src="//myserver/piwik/piwik.php?idsite=1" style="border:0;" alt="" /></p></noscript>
<!-- End Piwik Code -->
I want to use javascript code of piwik to track my website which is built on express.
I had put my javascript code in app.js in express.
But found error.
my javascript code is:-
<script type="text/javascript">
var _paq = _paq || [];
_paq.push(["trackPageView"]);
_paq.push(["enableLinkTracking"]);
(function() {
var u=(("https:" == document.location.protocol) ? "https" : "http") + "://localhost/piwik/";
_paq.push(["setTrackerUrl", u+"piwik.php"]);
_paq.push(["setSiteId", "1"]);
var d=document, g=d.createElement("script"), s=d.getElementsByTagName("script")[0]; g.type="text/javascript";
g.defer=true; g.async=true; g.src=u+"piwik.js"; s.parentNode.insertBefore(g,s);
})();
</script>
You can't run the client-side code for Piwik directly on Node.js.
But there are specific Node clients that you can use instead:
nodejs-piwik
nodejs-piwik-api