Integrate Clevertap in Vuejs Web application - javascript

I am having a task to integrate clevertap with vuejs frontend. but clevertap is undefined, how can i declare clevertap in vuejs?
clevertap.event.push("Product Viewed", {
"Product name":"Casio Chronograph Watch",
"Category":"Mens Accessories",
"Price":59.99,
});

You could either import https://github.com/CleverTap/clevertap-web-sdk into your project which will give you the clevertap object or alternatively add the following script to your app's HTML
<script type="text/javascript">
var clevertap = {event:[], profile:[], account:[], onUserLogin:[], notifications:[], privacy:[]};
// replace with the CLEVERTAP_ACCOUNT_ID with the actual ACCOUNT ID value from your Dashboard -> Settings page
clevertap.account.push({"id": "CLEVERTAP_ACCOUNT_ID"});
clevertap.privacy.push({optOut: false}); //set the flag to true, if the user of the device opts out of sharing their data
clevertap.privacy.push({useIP: false}); //set the flag to true, if the user agrees to share their IP data
(function () {
var wzrk = document.createElement('script');
wzrk.type = 'text/javascript';
wzrk.async = true;
wzrk.src = ('https:' == document.location.protocol ? 'https://d2r1yp2w7bby2u.cloudfront.net' : 'http://static.clevertap.com') + '/js/a.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(wzrk, s);
})();
</script>
Source: https://developer.clevertap.com/docs/web-quickstart-guide
This will create a clevertap object globally and you can use window.clevertap within your vue app.

Related

Python lxml Cleaner module was not working as expected?

In my webscraper some of the content is coming with advertisements and some java script functions in it. Like the below;
(function() { var infAds = document.createElement('script'); infAds.async = true; infAds.type = 'text/javascript'; var useSSL = 'https:' == document.location.protocol; infAds.src = (useSSL ? 'https:' : 'http:') + '//d.infeed.id/widget-50716010/loader/all/'; var node = document.getElementById('cont-50716010-all'); node.parentNode.insertBefore(infAds, node); })();
I have used lxml.html.clean.Cleaner to remove the scripts and styles from the content. But it is not all removing what i expected. I tried like the below;
from lxml.html.clean import Cleaner
cleaner = Cleaner()
cleaner.javascript = True
cleaner.scripts = True
content = "Page content"
clean_content = cleaner.clean_html(content)
print(clean_content)
But if i use
__clean_content = lxml.html.toString(cleaner.clean_html(content))
__
i am getting the below type error;
TypeError: Type 'str' cannot be serialized.
Using regex also i have tried, it wasn't worked out too. Any suggestions or help would be greatly appreciable!
Thanks in advance.

Two custom searches in same page disables search predictions

While using different styles for larger displays and mobiles, I was forced to insert two google custom search boxes in same page. The search still works perfectly but the issue is that search predictions are no longer available after inserting the second search box.
(function() {
var cx = '*****************:**********';
var gcse = document.createElement('script');
gcse.type = 'text/javascript';
gcse.async = true;
gcse.src = 'https://cse.google.com/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(gcse, s);
})();
The same code is using twice in the same page(especially repeated id usage) which causes the conflict I think. Already referred similar posts 'How to have multiple Google Custom Search field on the same page' and 'Multiple GCSE's on page at one time', but those are not solutions for the situation which I'm facing. How to enable both search boxes in same page work in a similar manner without causing conflict?
I'm currently experimenting with this. Getting 2 cse's with a different cx on the same page isn't that hard, but can't get the suggestions working. The v2 control api method description isn't very clear.
But with a single cx you can just do this:
html:
<div id="first"></div>
<br/>
<div id="second"></div>
js:
var renderSearchElement = function() {
google.search.cse.element.render({
div: "first",
tag: 'search'
});
google.search.cse.element.render({
div: "second",
tag: 'search'
});
};
var myCallback = function() {
if (document.readyState == 'complete') {
renderSearchElement();
} else {
google.setOnLoadCallback(renderSearchElement, true);
}
};
window.__gcse = {
parsetags: 'explicit',
callback: myCallback
};
var loadElements = function() {
var cx = '*****************:**********';
var gcse = document.createElement('script');
gcse.type = 'text/javascript';
gcse.async = true;
gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//cse.google.com/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(gcse, s);
}
loadElements();
demo:
https://jsfiddle.net/501g48d4/
CSE v2 control API and render params: https://developers.google.com/custom-search/docs/element

Integrate NotifyVisitors Javascript Code OPencart

I want to add the following javascript code into the footer of Opencart (2.0.3) to integrate notifyvisitors app for my website.
But I don't know how and where to add javascript code to enable notifyvisitors app.
<div id='notifyvisitorstag'></div>
<script>
var notify_visitors = window.notify_visitors || {};
(function() {
notify_visitors.auth = { bid_e : '7E8xxxxxxxxxxxx561', bid : '0000`enter code here`', t : '420'};
var script = document.createElement('script');script.async = true;
script.src = (document.location.protocol == 'https:' ? "//d2933uxo1uhve4.cloudfront.net" : "//cdn.notifyvisitors.com") + '/js/notify-visitors-1.0.js';
var entry = document.getElementsByTagName('script')[0];
entry.parentNode.insertBefore(script, entry);
})();
</script>
Please guide.
Thanks.
Notifyvisitors updated plugin is now available at official opencart extension store.

Getting result from FB.api() into abap with javascript

I'm newbie on sap abap and sap crm and javascript. I'm trying to get facebook's page stream into my bsp app.
<%#page language="abap" %>
<%#extension name="htmlb" prefix="htmlb" %>
<htmlb:content id = "content"
design = "design2003"
controlRendering = "sap"
rtlAutoSwitch = "true" >
<htmlb:page title="jQuery" >
<htmlb:form id = "formBody"
method = "post" >
<script type="text/javascript" src="jquery-1.7.2.min.js" ></script>
<script>
function getPosts() {
FB.api('/8****5833028****/feed', 'get', { access_token : '7***5058***8**7|qJzB0*****VRC***YfE****wpk4' }, function(normalData) {
if (!normalData || normalData.error) {
alert('Error occured');
} else {
alert(normalData.data[0].from.name);
$('<div class="result"></div>')
.append('<h3>' + normalData.data[0].from.name + '</h3>')
.append('<h3>' + normalData.data[0].message + '</h3>')
.appendTo('body');
document.getElementById("gv_response").value = normalData;
}
});
}
</script>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '7***5058***8**7',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
};
(function() {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
</script>
Facebook
<htmlb:inputField id = "gv_response"
type = "string"
visible = "true"
size = "120" />
<htmlb:button id = "myButton11"
text = "onClick"
onClick = "getPosts" />
<body>
<div class="result"></div>
</body>
</htmlb:form>
</htmlb:page>
</htmlb:content>
With above code, i took all data and i write user name on page from facebook wall's feed. My access_token and connection is right.
Here's my question, how can i pass value into bsp app.'s variable.
- should i parse value in javascript and pass only asked value's?
- or is that possible take all value into bsp's variable and serialize in bsp app?
note: i know there's an abap function can serialize jsons.
For now i choose a way like this; I created all possible field i should use with html(or htmlb) code and those fields were hidden. With javascript code, i give my asked value into those fields.
Fields per feed sample:
<htmlb:inputField id = "fb_002_uname" />
<htmlb:inputField id = "fb_002_umssg" />
<htmlb:inputField id = "fb_002_ctime" />
<htmlb:inputField id = "fb_002_utime" />
Javascript code:
document.getElementById("fb_002_uname").value = normalData.data[1].from.name;
document.getElementById("fb_002_umssg").value = normalData.data[1].message;
document.getElementById("fb_002_ctime").value = normalData.data[1].created_time;
document.getElementById("fb_002_utime").value = normalData.data[1].updated_time;
And in abap:
request->get_form_fields( CHANGING fields = lt_data ).
like these i'll get all fields value.
Why i choose like this way?
Because i couldn't get json from facebook.
If you know how can i get json string from facebook, please help me and if you can with sample.
Thank you.
Utku

How can I specify as_sitesearch in v2 of Google Site Search / Custom Search?

I have a Google Custom Search (that will be a Site Search in the future) and I'd like to use the snippet that Google provides:
<script>
(function() {
var cx = '...';
var gcse = document.createElement('script'); gcse.type = 'text/javascript'; gcse.async = true;
gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
'//www.google.com/cse/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(gcse, s);
})();
</script>
<gcse:search></gcse:search>
I need to restrict it to certain urls. When using the xml api, you can use the parameter as_sitesearch to specify this filter.. is there a way to do this with the code above?
with this I can now access the google.search.cse object before the search is loaded.. but I still don't know parameter:
<script>
var myCallback = function() {
if (document.readyState == 'complete') {
// Document is ready when CSE element is initialized.
// Render an element with both search box and search results in div with id 'test'.
google.search.cse.element.render(
{
div: "test",
tag: 'search'
});
} else {
// Document is not ready yet, when CSE element is initialized.
google.setOnLoadCallback(function() {
// Render an element with both search box and search results in div with id 'test'.
google.search.cse.element.render(
{
div: "test",
tag: 'search'
});
}, true);
}
};
// Insert it before the CSE code snippet so that cse.js can take the script
// parameters, like parsetags, callbacks.
window.__gcse = {
parsetags: 'explicit',
callback: myCallback
};
(function() {
var cx = '007407192365638902354:eyxoavi7oa0';
var gcse = document.createElement('script'); gcse.type = 'text/javascript'; gcse.async = true;
gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
'//www.google.com/cse/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(gcse, s);
})();
</script>
<style>
.gsc-control-cse * {
box-sizing:content-box;
}
</style>
Yes you can.
Use a hidden field inside your search form:
<input type="hidden" name="as_sitesearch" value="your_url_here/directory">
I've got the same question. The only way I have been able to restrict the search to a particular folder in Google Site Search version 2 is to hard-code it into the element:
<gcse:search as_sitesearch="www.mydomain.com/site1"></gcse:search>
It would be great if there was a way to add as_sitesearch via JavaScript, like with version 1.
To restrict to certain urls:
<gcse:searchbox-only as_sitesearch="mydomain.com" resultsUrl="http://mydomain.com/search-results/" enableAutoComplete="false"></gcse:searchbox-only>
Be sure to replace mydomain.com with the appropriate domain that you want to restrict to.

Categories