Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

init component mip-mm-ping-btn #1219

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/mip-mm-ping-btn/README.md
Original file line number Diff line number Diff line change
@@ -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
<mip-mm-ping-btn>
自定义内容,可以嵌套其他组件
</mip-mm-ping-btn>
```

## 属性

### {属性名}

说明:{说明}
必选项:{是|否}
类型:{类型}
取值范围:{取值范围}
单位:{单位}
默认值:{默认值}

## 注意事项

84 changes: 84 additions & 0 deletions src/mip-mm-ping-btn/mip-mm-ping-btn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/**
* @file mip-mm-ping-btn 组件
* @author [email protected]
*/

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;
});
17 changes: 17 additions & 0 deletions src/mip-mm-ping-btn/mip-mm-ping-btn.less
Original file line number Diff line number Diff line change
@@ -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;
}
14 changes: 14 additions & 0 deletions src/mip-mm-ping-btn/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "mip-mm-ping-btn",
"version": "1.0.0",
"description": "点击按钮的打点功能",
"contributors": [
{
"name": "jxintang",
"email": "[email protected]"
}
],
"engines": {
"mip": ">=1.1.0"
}
}