From 90ab6d4d1710b344b1799c79e4bb9dccb11ad7cc Mon Sep 17 00:00:00 2001 From: tangjingxin Date: Mon, 23 Jul 2018 11:49:55 +0800 Subject: [PATCH 1/2] init component mip-mm-ping-btn --- src/mip-mm-ping-btn/README.md | 32 +++++++++ src/mip-mm-ping-btn/mip-mm-ping-btn.js | 84 ++++++++++++++++++++++++ src/mip-mm-ping-btn/mip-mm-ping-btn.less | 17 +++++ src/mip-mm-ping-btn/package.json | 3 + 4 files changed, 136 insertions(+) create mode 100644 src/mip-mm-ping-btn/README.md create mode 100644 src/mip-mm-ping-btn/mip-mm-ping-btn.js create mode 100644 src/mip-mm-ping-btn/mip-mm-ping-btn.less create mode 100644 src/mip-mm-ping-btn/package.json diff --git a/src/mip-mm-ping-btn/README.md b/src/mip-mm-ping-btn/README.md new file mode 100644 index 000000000..1c67e9b16 --- /dev/null +++ b/src/mip-mm-ping-btn/README.md @@ -0,0 +1,32 @@ +# mip-mm-ping-btn + +点击按钮的打点功能 + +标题|内容 +----|---- +类型|通用 +支持布局|responsive,fixed-height,fill,container,fixed +所需脚本|https://c.mipcdn.com/static/v1/mip-mm-ping-btn/mip-mm-ping-btn.js + +## 示例 + +### 基本用法 +```html + + 自定义内容,可以嵌套其他组件 + +``` + +## 属性 + +### {属性名} + +说明:{说明} +必选项:{是|否} +类型:{类型} +取值范围:{取值范围} +单位:{单位} +默认值:{默认值} + +## 注意事项 + diff --git a/src/mip-mm-ping-btn/mip-mm-ping-btn.js b/src/mip-mm-ping-btn/mip-mm-ping-btn.js new file mode 100644 index 000000000..8e2a05883 --- /dev/null +++ b/src/mip-mm-ping-btn/mip-mm-ping-btn.js @@ -0,0 +1,84 @@ +/** + * @file mip-mm-ping-btn 组件 + * @author jxintang@gmail.com + */ + +define(function (require) { + 'use strict'; + + var customElement = require('customElement').create(); + + /** + * 第一次进入可视区回调,只会执行一次 + */ + customElement.prototype.firstInviewCallback = function () { + // TODO + const baseUrl = 'https://ping.mm.taou.com/maimai/'; + var element = this.element; + element.addEventListener('click', function () { + var userAgent = navigator.userAgent || navigator.vendor || window.opera; + var query = getQueryString(); + var keywordid = 'sem_baidu'; // 默认值 + var url = window.location.pathname; + var urlsplit = url.split("/").slice(-1)[0]; + if (query.regfr) { + var arry = query.regfr.split('_'); + if (arry.length) { + keywordid = arry[arry.length - 1]; + } + } + + var url = window.location.pathname; + var urlsplit = url.split("/").slice(-1)[0]; + pingback(baseUrl + urlsplit + '?event=download'); + + // 判断android还是ios + if (/iPad|iPhone|iPod/g.test(userAgent)) { + window.location = `https://app.appsflyer.com/id718659370?af_prt=wushuang&pid=baidusearch_int&c=abtest&af_adset=city&af_ad=${keywordid}&af_click_lookback=7d`; + } else if (/android/i.test(userAgent)) { + window.location = `https://app.appsflyer.com/com.taou.maimai-default?af_prt=wushuang&pid=baidusearch_int&af_r=http://maimai.cn/dlc?c=Organic&c=abtest&af_adset=city&af_ad=${keywordid}&af_click_lookback=7d` + } + }); + }; + + /** + * 打点功能 + * @param {String} url 打点的url + * @param {Function} callback 打点后的回调地址 + */ + function pingback(url, callback) { + var xmlHttp = new XMLHttpRequest(); + xmlHttp.onreadystatechange = function () { + if (xmlHttp.readyState == 4 && xmlHttp.status == 200) + callback && callback(xmlHttp.responseText); + } + xmlHttp.open("GET", url, true); // true for asynchronous + xmlHttp.send(null); + } + + /** + * 解析页面的url(以对象结构进行返回) + */ + function getQueryString () { + var query_string = {}; + var query = window.location.search.substring(1); + var vars = query.split("&"); + for (var i = 0; i < vars.length; i++) { + var pair = vars[i].split("="); + // If first entry with this name + if (typeof query_string[pair[0]] === "undefined") { + query_string[pair[0]] = pair[1]; + // If second entry with this name + } else if (typeof query_string[pair[0]] === "string") { + var arr = [query_string[pair[0]], pair[1]]; + query_string[pair[0]] = arr; + // If third or later entry with this name + } else { + query_string[pair[0]].push(pair[1]); + } + } + return query_string; + }; + + return customElement; +}); diff --git a/src/mip-mm-ping-btn/mip-mm-ping-btn.less b/src/mip-mm-ping-btn/mip-mm-ping-btn.less new file mode 100644 index 000000000..144505697 --- /dev/null +++ b/src/mip-mm-ping-btn/mip-mm-ping-btn.less @@ -0,0 +1,17 @@ +/** + * @file mip-mm-ping-btn样式文件 + */ + +mip-mm-ping-btn { + height: 46px; + line-height: 46px; + box-shadow: rgba(0, 58, 89, 0.3) 0px 3px 15px 0px; + text-align: center; + font-size: 16px; + color: rgb(1, 158, 235); + margin: 0px 40px; + background: rgb(255, 255, 255); + border-radius: 50px; + width: 78vw; + border: none; +} diff --git a/src/mip-mm-ping-btn/package.json b/src/mip-mm-ping-btn/package.json new file mode 100644 index 000000000..49d1a202f --- /dev/null +++ b/src/mip-mm-ping-btn/package.json @@ -0,0 +1,3 @@ +{ + +} From 0a96929f6863ad99107520872de5df9580456a0f Mon Sep 17 00:00:00 2001 From: tangjingxin Date: Mon, 23 Jul 2018 11:59:10 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=9B=B4=E6=96=B0package.json=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mip-mm-ping-btn/package.json | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/mip-mm-ping-btn/package.json b/src/mip-mm-ping-btn/package.json index 49d1a202f..c07685d3b 100644 --- a/src/mip-mm-ping-btn/package.json +++ b/src/mip-mm-ping-btn/package.json @@ -1,3 +1,14 @@ { - + "name": "mip-mm-ping-btn", + "version": "1.0.0", + "description": "点击按钮的打点功能", + "contributors": [ + { + "name": "jxintang", + "email": "jxintang@gmail.com" + } + ], + "engines": { + "mip": ">=1.1.0" + } }